1 | /* Copyright © 2005-2007 Roger Leigh <rleigh@debian.org> |
---|
2 | * |
---|
3 | * schroot is free software: you can redistribute it and/or modify it |
---|
4 | * under the terms of the GNU General Public License as published by |
---|
5 | * the Free Software Foundation, either version 3 of the License, or |
---|
6 | * (at your option) any later version. |
---|
7 | * |
---|
8 | * schroot is distributed in the hope that it will be useful, but |
---|
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | * General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU General Public License |
---|
14 | * along with this program. If not, see |
---|
15 | * <http://www.gnu.org/licenses/>. |
---|
16 | * |
---|
17 | *********************************************************************/ |
---|
18 | |
---|
19 | #include <config.h> |
---|
20 | |
---|
21 | #include <sbuild/sbuild-i18n.h> |
---|
22 | |
---|
23 | #include "schroot-releaselock-options.h" |
---|
24 | |
---|
25 | #include <cstdlib> |
---|
26 | #include <iostream> |
---|
27 | |
---|
28 | #include <boost/format.hpp> |
---|
29 | #include <boost/program_options.hpp> |
---|
30 | |
---|
31 | using std::endl; |
---|
32 | using boost::format; |
---|
33 | using sbuild::_; |
---|
34 | namespace opt = boost::program_options; |
---|
35 | using namespace schroot_releaselock; |
---|
36 | |
---|
37 | const options::action_type options::ACTION_RELEASELOCK ("releaselock"); |
---|
38 | |
---|
39 | options::options (): |
---|
40 | schroot_base::options(), |
---|
41 | device(), |
---|
42 | pid(0), |
---|
43 | lock(_("Lock")) |
---|
44 | { |
---|
45 | } |
---|
46 | |
---|
47 | options::~options () |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | void |
---|
52 | options::add_options () |
---|
53 | { |
---|
54 | // Chain up to add basic options. |
---|
55 | schroot_base::options::add_options(); |
---|
56 | |
---|
57 | action.add(ACTION_RELEASELOCK); |
---|
58 | action.set_default(ACTION_RELEASELOCK); |
---|
59 | |
---|
60 | lock.add_options() |
---|
61 | ("device,d", opt::value<std::string>(&this->device), |
---|
62 | _("Device to unlock (full path)")) |
---|
63 | ("pid,p", opt::value<int>(&this->pid), |
---|
64 | _("Process ID owning the lock")); |
---|
65 | } |
---|
66 | |
---|
67 | void |
---|
68 | options::add_option_groups () |
---|
69 | { |
---|
70 | // Chain up to add basic option groups. |
---|
71 | schroot_base::options::add_option_groups(); |
---|
72 | |
---|
73 | #ifndef BOOST_PROGRAM_OPTIONS_DESCRIPTION_OLD |
---|
74 | if (!lock.options().empty()) |
---|
75 | #else |
---|
76 | if (!lock.primary_keys().empty()) |
---|
77 | #endif |
---|
78 | { |
---|
79 | visible.add(lock); |
---|
80 | global.add(lock); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void |
---|
85 | options::check_options () |
---|
86 | { |
---|
87 | // Chain up to check basic options. |
---|
88 | schroot_base::options::check_options(); |
---|
89 | |
---|
90 | if (this->action == ACTION_RELEASELOCK && |
---|
91 | this->device.empty()) |
---|
92 | throw opt::validation_error(_("No device specified")); |
---|
93 | } |
---|