dchroot-dsa-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 "dchroot-dsa-options.h"
00023 
00024 #include <sbuild/sbuild-util.h>
00025 
00026 #include <cstdlib>
00027 #include <iostream>
00028 
00029 #include <boost/format.hpp>
00030 #include <boost/program_options.hpp>
00031 
00032 using std::endl;
00033 using boost::format;
00034 namespace opt = boost::program_options;
00035 using namespace dchroot_dsa;
00036 
00037 options::options ():
00038   schroot::options_base()
00039 {
00040 }
00041 
00042 options::~options ()
00043 {
00044 }
00045 
00046 void
00047 options::add_options ()
00048 {
00049   schroot::options_base::add_options();
00050 
00051   general.add_options()
00052     ("listpaths,p",
00053      _("Print paths to available chroots"));
00054 
00055   chroot.add_options()
00056     ("all,a",
00057      _("Select all chroots"));
00058 
00059   chrootenv.add_options()
00060     ("directory,d", opt::value<std::string>(&this->directory),
00061      _("Directory to use"));
00062 }
00063 
00064 void
00065 options::check_options ()
00066 {
00067   schroot::options_base::check_options();
00068 
00069   if (vm.count("listpaths"))
00070     set_action(ACTION_LOCATION);
00071 
00072   if (vm.count("all"))
00073     {
00074       this->all = false;
00075       this->all_chroots = true;
00076       this->all_sessions = false;
00077     }
00078 
00079   // Always preserve environment.
00080   this->preserve = true;
00081 
00082   // If no chroots specified, use the first non-option.
00083   if (this->chroots.empty() && !this->command.empty())
00084     {
00085       this->chroots.push_back(this->command[0]);
00086       this->command.erase(this->command.begin());
00087     }
00088 
00089   // dchroot-dsa only allows one command.
00090   if (this->command.size() > 1)
00091     throw opt::validation_error(_("Only one command may be specified"));
00092 
00093   if (!this->command.empty() &&
00094       !sbuild::is_absname(this->command[0]))
00095     throw opt::validation_error(_("Command must have an absolute path"));
00096 
00097   if (this->chroots.empty() && !all_used() &&
00098       (this->action != ACTION_CONFIG &&
00099        this->action != ACTION_INFO &&
00100        this->action != ACTION_LIST &&
00101        this->action != ACTION_LOCATION &&
00102        this->action != ACTION_HELP &&
00103        this->action != ACTION_VERSION))
00104     throw opt::validation_error(_("No chroot specified"));
00105 }

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