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

Generated on Mon Jan 21 00:38:28 2008 for schroot by  doxygen 1.5.4