source: trunk/debathena/third/schroot/bin/schroot-base/schroot-base-main.cc @ 24314

Revision 24314, 3.6 KB checked in by geofft, 14 years ago (diff)
In schroot: * Merge with Debian unstable; remaining changes: - Backport to Karmic, and adjust build-deps.
Line 
1/* Copyright © 2005-2009  Roger Leigh <rleigh@debian.org>
2 *
3 * schroot is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * schroot is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#include <config.h>
20
21#include <sbuild/sbuild-i18n.h>
22#include <sbuild/sbuild-log.h>
23#include <sbuild/sbuild-types.h>
24
25#include "schroot-base-main.h"
26
27#include <cstdlib>
28#include <ctime>
29#include <iostream>
30
31#include <syslog.h>
32
33#include <boost/format.hpp>
34
35using std::endl;
36using boost::format;
37using sbuild::_;
38using namespace schroot_base;
39
40main::main (std::string const&  program_name,
41            std::string const&  program_usage,
42            options::ptr const& program_options,
43            bool                use_syslog):
44  program_name(program_name),
45  program_usage(program_usage),
46  program_options(program_options),
47  use_syslog(use_syslog)
48{
49}
50
51main::~main ()
52{
53}
54
55void
56main::action_version (std::ostream& stream)
57{
58  // TRANSLATORS: %1% = program name
59  // TRANSLATORS: %2% = program version
60  // TRANSLATORS: %3% = release date
61  format fmt(_("%1% (Debian sbuild) %2% (%3%)\n"));
62  fmt % this->program_name % VERSION % sbuild::gmdate(RELEASE_DATE);
63
64  format feature("  %1$-12s %2%\n");
65
66  stream << fmt
67         << _("Written by Roger Leigh") << '\n' << '\n'
68    // TRANSLATORS: '(C)' is a copyright symbol and '-' is an en-dash.
69         << _("Copyright (C) 2004-2010 Roger Leigh") << '\n'
70         << _("This is free software; see the source for copying conditions.  There is NO\n"
71              "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")
72         << '\n'
73         << _("Configured features:") << '\n';
74#ifdef SBUILD_FEATURE_DEVLOCK
75  stream << feature % "DEVLOCK" % _("Device locking");
76#endif
77#ifdef SBUILD_FEATURE_PAM
78  stream << feature % "PAM" % _("Pluggable Authentication Modules");
79#endif
80#ifdef SBUILD_FEATURE_PERSONALITY
81  stream << feature % "PERSONALITY" % _("Linux kernel Application Binary Interface switching");
82#endif
83#ifdef SBUILD_FEATURE_UNION
84  stream << feature % "UNION" % _("Support for filesystem unioning");
85#endif
86  stream << std::flush;
87}
88
89void
90main::action_help (std::ostream& stream)
91{
92  stream
93    << _("Usage:") << '\n'
94    << "  " << this->program_name << "  "
95    << this->program_usage << std::endl;
96
97  stream << this->program_options->get_visible_options() << std::flush;
98}
99
100int
101main::run (int   argc,
102           char *argv[])
103{
104  try
105    {
106      this->program_options->parse(argc, argv);
107
108#ifdef SBUILD_DEBUG
109      sbuild::debug_level = sbuild::DEBUG_CRITICAL;
110#endif
111
112      if (this->use_syslog)
113        openlog(this->program_name.c_str(), LOG_PID|LOG_NDELAY, LOG_AUTHPRIV);
114
115      int status = run_impl();
116
117      closelog();
118
119      return status;
120    }
121  catch (std::exception const& e)
122    {
123      sbuild::log_exception_error(e);
124
125      try
126        {
127          dynamic_cast<boost::program_options::error const&>(e);
128          sbuild::log_info()
129            // TRANSLATORS: %1% = program name
130            << format(_("Run \"%1% --help\" to list usage example and all available options"))
131            % argv[0]
132            << endl;
133        }
134      catch (std::bad_cast const& discard)
135        {
136        }
137
138      if (this->use_syslog)
139        closelog();
140
141      return EXIT_FAILURE;
142    }
143}
Note: See TracBrowser for help on using the repository browser.