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 "schroot-options.h" |
---|
22 | |
---|
23 | #include <cstdlib> |
---|
24 | #include <iostream> |
---|
25 | |
---|
26 | #include <boost/format.hpp> |
---|
27 | #include <boost/program_options.hpp> |
---|
28 | |
---|
29 | using std::endl; |
---|
30 | using boost::format; |
---|
31 | using sbuild::_; |
---|
32 | namespace opt = boost::program_options; |
---|
33 | using namespace schroot; |
---|
34 | |
---|
35 | options::options (): |
---|
36 | options_base() |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | options::~options () |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | void |
---|
45 | options::add_options () |
---|
46 | { |
---|
47 | // Chain up to add general schroot options. |
---|
48 | options_base::add_options(); |
---|
49 | |
---|
50 | actions.add_options() |
---|
51 | ("location", |
---|
52 | _("Print location of selected chroots")); |
---|
53 | |
---|
54 | chroot.add_options() |
---|
55 | ("all,a", |
---|
56 | _("Select all chroots and active sessions")) |
---|
57 | ("all-chroots", |
---|
58 | _("Select all chroots")) |
---|
59 | ("all-sessions", |
---|
60 | _("Select all active sessions")); |
---|
61 | |
---|
62 | chrootenv.add_options() |
---|
63 | ("directory,d", opt::value<std::string>(&this->directory), |
---|
64 | _("Directory to use")) |
---|
65 | ("user,u", opt::value<std::string>(&this->user), |
---|
66 | _("Username (default current user)")) |
---|
67 | ("preserve-environment,p", |
---|
68 | _("Preserve user environment")); |
---|
69 | |
---|
70 | session_actions.add_options() |
---|
71 | ("automatic-session", |
---|
72 | _("Begin, run and end a session automatically (default)")) |
---|
73 | ("begin-session,b", |
---|
74 | _("Begin a session; returns a session ID")) |
---|
75 | ("recover-session", |
---|
76 | _("Recover an existing session")) |
---|
77 | ("run-session,r", |
---|
78 | _("Run an existing session")) |
---|
79 | ("end-session,e", |
---|
80 | _("End an existing session")); |
---|
81 | |
---|
82 | session_options.add_options() |
---|
83 | ("session-name,n", opt::value<std::string>(&this->session_name), |
---|
84 | _("Session name (defaults to an automatically generated name)")) |
---|
85 | ("force,f", |
---|
86 | _("Force operation, even if it fails")); |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | void |
---|
91 | options::check_options () |
---|
92 | { |
---|
93 | // Chain up to check general schroot options. |
---|
94 | options_base::check_options(); |
---|
95 | |
---|
96 | if (vm.count("location")) |
---|
97 | this->action = ACTION_LOCATION; |
---|
98 | |
---|
99 | if (vm.count("all")) |
---|
100 | this->all = true; |
---|
101 | if (vm.count("all-chroots")) |
---|
102 | this->all_chroots = true; |
---|
103 | if (vm.count("all-sessions")) |
---|
104 | this->all_sessions = true; |
---|
105 | |
---|
106 | if (vm.count("preserve-environment")) |
---|
107 | this->preserve = true; |
---|
108 | |
---|
109 | if (vm.count("automatic-session")) |
---|
110 | this->action = ACTION_SESSION_AUTO; |
---|
111 | if (vm.count("begin-session")) |
---|
112 | this->action = ACTION_SESSION_BEGIN; |
---|
113 | if (vm.count("recover-session")) |
---|
114 | this->action = ACTION_SESSION_RECOVER; |
---|
115 | if (vm.count("run-session")) |
---|
116 | this->action = ACTION_SESSION_RUN; |
---|
117 | if (vm.count("end-session")) |
---|
118 | this->action = ACTION_SESSION_END; |
---|
119 | if (vm.count("force")) |
---|
120 | this->session_force = true; |
---|
121 | |
---|
122 | if (this->all == true) |
---|
123 | { |
---|
124 | this->all_chroots = true; |
---|
125 | this->all_sessions = true; |
---|
126 | } |
---|
127 | } |
---|