schroot-options.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 "schroot-options.h"
00022 
00023 #include <cstdlib>
00024 #include <iostream>
00025 
00026 #include <boost/format.hpp>
00027 #include <boost/program_options.hpp>
00028 
00029 using std::endl;
00030 using boost::format;
00031 using sbuild::_;
00032 namespace opt = boost::program_options;
00033 using namespace schroot;
00034 
00035 options::options ():
00036   options_base()
00037 {
00038 }
00039 
00040 options::~options ()
00041 {
00042 }
00043 
00044 void
00045 options::add_options ()
00046 {
00047   // Chain up to add general schroot options.
00048   options_base::add_options();
00049 
00050   actions.add_options()
00051     ("location",
00052      _("Print location of selected chroots"));
00053 
00054   chroot.add_options()
00055     ("all,a",
00056      _("Select all chroots and active sessions"))
00057     ("all-chroots",
00058      _("Select all chroots"))
00059     ("all-sessions",
00060      _("Select all active sessions"));
00061 
00062   chrootenv.add_options()
00063     ("directory,d", opt::value<std::string>(&this->directory),
00064      _("Directory to use"))
00065     ("user,u", opt::value<std::string>(&this->user),
00066      _("Username (default current user)"))
00067     ("preserve-environment,p",
00068      _("Preserve user environment"));
00069 
00070   session_actions.add_options()
00071     ("automatic-session",
00072      _("Begin, run and end a session automatically (default)"))
00073     ("begin-session,b",
00074      _("Begin a session; returns a session ID"))
00075     ("recover-session",
00076      _("Recover an existing session"))
00077     ("run-session,r",
00078      _("Run an existing session"))
00079     ("end-session,e",
00080      _("End an existing session"));
00081 
00082   session_options.add_options()
00083     ("session-name,n", opt::value<std::string>(&this->session_name),
00084      _("Session name (defaults to an automatically generated name)"))
00085     ("force,f",
00086      _("Force operation, even if it fails"));
00087 }
00088 
00089 
00090 void
00091 options::check_options ()
00092 {
00093   // Chain up to check general schroot options.
00094   options_base::check_options();
00095 
00096   if (vm.count("location"))
00097     this->action = ACTION_LOCATION;
00098 
00099   if (vm.count("all"))
00100     this->all = true;
00101   if (vm.count("all-chroots"))
00102     this->all_chroots = true;
00103   if (vm.count("all-sessions"))
00104     this->all_sessions = true;
00105 
00106   if (vm.count("preserve-environment"))
00107     this->preserve = true;
00108 
00109   if (vm.count("automatic-session"))
00110     this->action = ACTION_SESSION_AUTO;
00111   if (vm.count("begin-session"))
00112     this->action = ACTION_SESSION_BEGIN;
00113   if (vm.count("recover-session"))
00114     this->action = ACTION_SESSION_RECOVER;
00115   if (vm.count("run-session"))
00116     this->action = ACTION_SESSION_RUN;
00117   if (vm.count("end-session"))
00118     this->action = ACTION_SESSION_END;
00119   if (vm.count("force"))
00120     this->session_force = true;
00121 
00122   if (this->all == true)
00123     {
00124       this->all_chroots = true;
00125       this->all_sessions = true;
00126     }
00127 }

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