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

Generated on Sun Jul 8 21:23:54 2007 for schroot by  doxygen 1.5.2