00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00058
00059
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
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
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 }