source: trunk/debathena/third/schroot/bin/dchroot-dsa/dchroot-dsa-options.cc @ 24167

Revision 24167, 2.7 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
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 "dchroot-dsa-options.h"
22
23#include <sbuild/sbuild-util.h>
24
25#include <cstdlib>
26#include <iostream>
27
28#include <boost/format.hpp>
29#include <boost/program_options.hpp>
30
31using std::endl;
32using sbuild::_;
33using boost::format;
34namespace opt = boost::program_options;
35using namespace dchroot_dsa;
36
37options::options ():
38  schroot::options_base()
39{
40}
41
42options::~options ()
43{
44}
45
46void
47options::add_options ()
48{
49  // Chain up to add general schroot options.
50  schroot::options_base::add_options();
51
52  actions.add_options()
53    ("listpaths,p",
54     _("Print paths to available chroots"));
55
56  chroot.add_options()
57    ("all,a",
58     _("Select all chroots"));
59
60  chrootenv.add_options()
61    ("directory,d", opt::value<std::string>(&this->directory),
62     _("Directory to use"));
63}
64
65void
66options::check_options ()
67{
68  // Chain up to check general schroot options.
69  schroot::options_base::check_options();
70
71  if (vm.count("listpaths"))
72    this->action = ACTION_LOCATION;
73
74  if (vm.count("all"))
75    {
76      this->all = false;
77      this->all_chroots = true;
78      this->all_sessions = false;
79    }
80
81  // Always preserve environment.
82  this->preserve = true;
83
84  // If no chroots specified, use the first non-option.
85  if (this->chroots.empty() && !this->command.empty())
86    {
87      this->chroots.push_back(this->command[0]);
88      this->command.erase(this->command.begin());
89    }
90
91  // dchroot-dsa only allows one command.
92  if (this->command.size() > 1)
93    throw opt::validation_error(_("Only one command may be specified"));
94
95  if (!this->command.empty() &&
96      !sbuild::is_absname(this->command[0]))
97    throw opt::validation_error(_("Command must have an absolute path"));
98
99  if (this->chroots.empty() && !all_used() &&
100      (this->action != ACTION_CONFIG &&
101       this->action != ACTION_INFO &&
102       this->action != ACTION_LIST &&
103       this->action != ACTION_LOCATION &&
104       this->action != ACTION_HELP &&
105       this->action != ACTION_VERSION))
106    throw opt::validation_error(_("No chroot specified"));
107}
Note: See TracBrowser for help on using the repository browser.