schroot-options.cc

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  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 "schroot-options.h"
00023 
00024 #include <cstdlib>
00025 #include <iostream>
00026 
00027 #include <boost/format.hpp>
00028 #include <boost/program_options.hpp>
00029 
00030 using std::endl;
00031 using boost::format;
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   options_base::add_options();
00048 
00049   general.add_options()
00050     ("location",
00051      _("Print location of selected chroots"));
00052 
00053   chroot.add_options()
00054     ("all,a",
00055      _("Select all chroots and active sessions"))
00056     ("all-chroots",
00057      _("Select all chroots"))
00058     ("all-sessions",
00059      _("Select all active sessions"));
00060 
00061   chrootenv.add_options()
00062     ("directory,d", opt::value<std::string>(&this->directory),
00063      _("Directory to use"))
00064     ("user,u", opt::value<std::string>(&this->user),
00065      _("Username (default current user)"))
00066     ("preserve-environment,p",
00067      _("Preserve user environment"));
00068 
00069   session.add_options()
00070     ("begin-session,b",
00071      _("Begin a session; returns a session ID"))
00072     ("recover-session",
00073      _("Recover an existing session"))
00074     ("run-session,r",
00075      _("Run an existing session"))
00076     ("end-session,e",
00077      _("End an existing session"))
00078     ("force,f",
00079      _("Force operation, even if it fails"));
00080 }
00081 
00082 
00083 void
00084 options::check_options ()
00085 {
00086   options_base::check_options();
00087 
00088   if (vm.count("location"))
00089     set_action(ACTION_LOCATION);
00090 
00091   if (vm.count("all"))
00092     this->all = true;
00093   if (vm.count("all-chroots"))
00094     this->all_chroots = true;
00095   if (vm.count("all-sessions"))
00096     this->all_sessions = true;
00097 
00098   if (vm.count("preserve-environment"))
00099     this->preserve = true;
00100 
00101   if (vm.count("begin-session"))
00102     set_action(ACTION_SESSION_BEGIN);
00103   if (vm.count("recover-session"))
00104     set_action(ACTION_SESSION_RECOVER);
00105   if (vm.count("run-session"))
00106     set_action(ACTION_SESSION_RUN);
00107   if (vm.count("end-session"))
00108     set_action(ACTION_SESSION_END);
00109   if (vm.count("force"))
00110     this->session_force = true;
00111 
00112   if (this->all == true)
00113     {
00114       this->all_chroots = true;
00115       this->all_sessions = true;
00116     }
00117 }

Generated on Sat Jan 27 16:11:04 2007 for schroot by  doxygen 1.5.1