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 <sbuild/sbuild-i18n.h>
00023
00024 #include "schroot-releaselock-options.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 schroot_releaselock;
00036
00037 options::options ():
00038 schroot_base::options(),
00039 action(ACTION_RELEASELOCK),
00040 device(),
00041 pid(0),
00042 lock(_("Lock"))
00043 {
00044 }
00045
00046 options::~options ()
00047 {
00048 }
00049
00050 void
00051 options::add_options ()
00052 {
00053 schroot_base::options::add_options();
00054
00055 lock.add_options()
00056 ("device,d", opt::value<std::string>(&this->device),
00057 _("Device to unlock (full path)"))
00058 ("pid,p", opt::value<int>(&this->pid),
00059 _("Process ID owning the lock"));
00060 }
00061
00062 void
00063 options::add_option_groups ()
00064 {
00065 schroot_base::options::add_option_groups();
00066
00067 #ifndef BOOST_PROGRAM_OPTIONS_DESCRIPTION_OLD
00068 if (!lock.options().empty())
00069 #else
00070 if (!lock.primary_keys().empty())
00071 #endif
00072 {
00073 visible.add(lock);
00074 global.add(lock);
00075 }
00076 }
00077
00078 void
00079 options::check_options ()
00080 {
00081 schroot_base::options::check_options();
00082
00083 if (vm.count("help"))
00084 set_action(ACTION_HELP);
00085
00086 if (vm.count("version"))
00087 set_action(ACTION_VERSION);
00088
00089 if (this->device.empty() &&
00090 this->action != ACTION_HELP &&
00091 this->action != ACTION_VERSION)
00092 throw opt::validation_error(_("No device specified"));
00093 }
00094
00095 void
00096 options::set_action (action_type action)
00097 {
00098 if (this->action != ACTION_RELEASELOCK)
00099 throw opt::validation_error(_("Only one action may be specified"));
00100
00101 this->action = action;
00102 }