00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <config.h>
00020
00021 #include "dchroot-dsa-options.h"
00022
00023 #include <sbuild/sbuild-util.h>
00024
00025 #include <cstdlib>
00026 #include <iostream>
00027
00028 #include <boost/format.hpp>
00029 #include <boost/program_options.hpp>
00030
00031 using std::endl;
00032 using sbuild::_;
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
00050 schroot::options_base::add_options();
00051
00052 actions.add_options()
00053 ("listpaths,p",
00054 _("Print paths to available chroots"));
00055
00056 chroot.add_options()
00057 ("all,a",
00058 _("Select all chroots"));
00059
00060 chrootenv.add_options()
00061 ("directory,d", opt::value<std::string>(&this->directory),
00062 _("Directory to use"));
00063 }
00064
00065 void
00066 options::check_options ()
00067 {
00068
00069 schroot::options_base::check_options();
00070
00071 if (vm.count("listpaths"))
00072 this->action = ACTION_LOCATION;
00073
00074 if (vm.count("all"))
00075 {
00076 this->all = false;
00077 this->all_chroots = true;
00078 this->all_sessions = false;
00079 }
00080
00081
00082 this->preserve = true;
00083
00084
00085 if (this->chroots.empty() && !this->command.empty())
00086 {
00087 this->chroots.push_back(this->command[0]);
00088 this->command.erase(this->command.begin());
00089 }
00090
00091
00092 if (this->command.size() > 1)
00093 throw opt::validation_error(_("Only one command may be specified"));
00094
00095 if (!this->command.empty() &&
00096 !sbuild::is_absname(this->command[0]))
00097 throw opt::validation_error(_("Command must have an absolute path"));
00098
00099 if (this->chroots.empty() && !all_used() &&
00100 (this->action != ACTION_CONFIG &&
00101 this->action != ACTION_INFO &&
00102 this->action != ACTION_LIST &&
00103 this->action != ACTION_LOCATION &&
00104 this->action != ACTION_HELP &&
00105 this->action != ACTION_VERSION))
00106 throw opt::validation_error(_("No chroot specified"));
00107 }