schroot-releaselock-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 <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 }

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