aboutsummaryrefslogtreecommitdiff
path: root/paludis/args/deps_option_arg.cc
blob: 538ebcc59539e8bf1fc28f7578f3b053a346dc8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "deps_option_arg.hh"
#include "do_help.hh"
#include <paludis/util/stringify.hh>

using namespace paludis;
using namespace paludis::args;

namespace
{
    std::string def_to_string(const DepListDepsOption d)
    {
        if (-1 == d)
            return "none";

        switch (d)
        {
            case dl_deps_discard:
                return "discard";
            case dl_deps_pre:
                return "pre";
            case dl_deps_pre_or_post:
                return "pre-or-post";
            case dl_deps_post:
                return "post";
            case dl_deps_try_post:
                return "try-post";
            case last_dl_deps:
                ;
        };

        throw InternalError(PALUDIS_HERE, "Unexpected DepListDepsOption value");
    }
}

DepsOptionArg::DepsOptionArg(ArgsGroup * const grp, const std::string & ln,
        char sh, const std::string & desc, const DepListDepsOption def) :
    EnumArg(grp, ln, sh, desc,
            EnumArgOptions
            ("pre",                  "As pre dependencies")
            ("pre-or-post",          "As pre dependencies, or post dependencies where needed")
            ("post",                 "As post dependencies")
            ("try-post",             "As post dependencies, with no error for failures")
            ("discard",              "Discard"),
            def_to_string(def))
{
}

DepsOptionArg::~DepsOptionArg()
{
}

DepListDepsOption
DepsOptionArg::option() const
{
    if ("pre" == argument())
        return dl_deps_pre;
    if ("pre-or-post" == argument())
        return dl_deps_pre_or_post;
    if ("post" == argument())
        return dl_deps_post;
    if ("try-post" == argument())
        return dl_deps_try_post;
    if ("discard" == argument())
        return dl_deps_discard;

    throw DoHelp("Bad value for --" + long_name());
}