schroot-base-main.cc

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software; you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
00017  *
00018  *********************************************************************/
00019 
00020 #include <config.h>
00021 
00022 #include <sbuild/sbuild-i18n.h>
00023 #include <sbuild/sbuild-log.h>
00024 #include <sbuild/sbuild-types.h>
00025 
00026 #include "schroot-base-main.h"
00027 
00028 #include <cstdlib>
00029 #include <ctime>
00030 #include <iostream>
00031 #include <locale>
00032 
00033 #include <syslog.h>
00034 
00035 #include <boost/format.hpp>
00036 
00037 using std::endl;
00038 using boost::format;
00039 using namespace schroot_base;
00040 
00041 main::main (std::string const&  program_name,
00042             std::string const&  program_usage,
00043             options::ptr const& program_options):
00044   program_name(program_name),
00045   program_usage(program_usage),
00046   program_options(program_options)
00047 {
00048 }
00049 
00050 main::~main ()
00051 {
00052 }
00053 
00054 void
00055 main::action_version (std::ostream& stream)
00056 {
00057   // TRANSLATORS: %1% = program name
00058   // TRANSLATORS: %2% = program version
00059   // TRANSLATORS: %3% = release date
00060   format fmt(_("%1% (Debian sbuild) %2% (%3%)\n"));
00061   fmt % this->program_name % VERSION % sbuild::gmdate(RELEASE_DATE);
00062 
00063   stream << fmt
00064          << _("Written by Roger Leigh") << '\n' << '\n'
00065     // TRANSLATORS: '(C)' is a copyright symbol and '-' is an en-dash.
00066          << _("Copyright (C) 2004-2006 Roger Leigh") << '\n'
00067          << _("This is free software; see the source for copying conditions.  There is NO\n"
00068               "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")
00069          << std::flush;
00070 }
00071 
00072 void
00073 main::action_help (std::ostream& stream)
00074 {
00075   stream
00076     << _("Usage:") << '\n'
00077     << "  " << this->program_name << "  "
00078     << gettext(this->program_usage.c_str()) << std::endl;
00079 
00080   stream << this->program_options->get_visible_options() << std::flush;
00081 }
00082 
00083 int
00084 main::run (int   argc,
00085            char *argv[])
00086 {
00087   try
00088     {
00089       this->program_options->parse(argc, argv);
00090 
00091 #ifdef SBUILD_DEBUG
00092       sbuild::debug_level = sbuild::DEBUG_CRITICAL;
00093 #endif
00094 
00095       openlog("schroot", LOG_PID|LOG_NDELAY, LOG_AUTHPRIV);
00096 
00097       int status = run_impl();
00098 
00099       closelog();
00100 
00101       return status;
00102     }
00103   catch (std::exception const& e)
00104     {
00105       sbuild::log_exception_error(e);
00106 
00107       try
00108         {
00109           dynamic_cast<boost::program_options::error const&>(e);
00110           sbuild::log_info()
00111             // TRANSLATORS: %1% = program name
00112             << format(_("Run \"%1% --help\" to list usage example and all available options"))
00113             % argv[0]
00114             << endl;
00115         }
00116       catch (std::bad_cast const& discard)
00117         {
00118         }
00119 
00120       closelog();
00121 
00122       return EXIT_FAILURE;
00123     }
00124 }

Generated on Sat Jan 27 16:11:03 2007 for schroot by  doxygen 1.5.1