00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
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
00083 this->preserve = true;
00084
00085
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
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 }