schroot-base-main.cc

Go to the documentation of this file.
00001 /* Copyright © 2005-2007  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 
00032 #include <syslog.h>
00033 
00034 #include <boost/format.hpp>
00035 
00036 using std::endl;
00037 using boost::format;
00038 using sbuild::_;
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             bool                use_syslog):
00045   program_name(program_name),
00046   program_usage(program_usage),
00047   program_options(program_options),
00048   use_syslog(use_syslog)
00049 {
00050 }
00051 
00052 main::~main ()
00053 {
00054 }
00055 
00056 void
00057 main::action_version (std::ostream& stream)
00058 {
00059   // TRANSLATORS: %1% = program name
00060   // TRANSLATORS: %2% = program version
00061   // TRANSLATORS: %3% = release date
00062   format fmt(_("%1% (Debian sbuild) %2% (%3%)\n"));
00063   fmt % this->program_name % VERSION % sbuild::gmdate(RELEASE_DATE);
00064 
00065   stream << fmt
00066          << _("Written by Roger Leigh") << '\n' << '\n'
00067     // TRANSLATORS: '(C)' is a copyright symbol and '-' is an en-dash.
00068          << _("Copyright (C) 2004-2007 Roger Leigh") << '\n'
00069          << _("This is free software; see the source for copying conditions.  There is NO\n"
00070               "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")
00071          << std::flush;
00072 }
00073 
00074 void
00075 main::action_help (std::ostream& stream)
00076 {
00077   stream
00078     << _("Usage:") << '\n'
00079     << "  " << this->program_name << "  "
00080     << this->program_usage << std::endl;
00081 
00082   stream << this->program_options->get_visible_options() << std::flush;
00083 }
00084 
00085 int
00086 main::run (int   argc,
00087            char *argv[])
00088 {
00089   try
00090     {
00091       this->program_options->parse(argc, argv);
00092 
00093 #ifdef SBUILD_DEBUG
00094       sbuild::debug_level = sbuild::DEBUG_CRITICAL;
00095 #endif
00096 
00097       if (this->use_syslog)
00098         openlog(this->program_name.c_str(), LOG_PID|LOG_NDELAY, LOG_AUTHPRIV);
00099 
00100       int status = run_impl();
00101 
00102       closelog();
00103 
00104       return status;
00105     }
00106   catch (std::exception const& e)
00107     {
00108       sbuild::log_exception_error(e);
00109 
00110       try
00111         {
00112           dynamic_cast<boost::program_options::error const&>(e);
00113           sbuild::log_info()
00114             // TRANSLATORS: %1% = program name
00115             << format(_("Run \"%1% --help\" to list usage example and all available options"))
00116             % argv[0]
00117             << endl;
00118         }
00119       catch (std::bad_cast const& discard)
00120         {
00121         }
00122 
00123       if (this->use_syslog)
00124         closelog();
00125 
00126       return EXIT_FAILURE;
00127     }
00128 }

Generated on Sun Jul 8 21:23:55 2007 for schroot by  doxygen 1.5.2