diff options
-rw-r--r-- | paludis/args/args_option.cc | 9 | ||||
-rw-r--r-- | paludis/args/args_option.hh | 7 | ||||
-rw-r--r-- | paludis/args/args_visitor.cc | 8 |
3 files changed, 18 insertions, 6 deletions
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc index 821669daa..cecefa038 100644 --- a/paludis/args/args_option.cc +++ b/paludis/args/args_option.cc @@ -130,16 +130,19 @@ AliasArg::forwardable_args() const } StringArg::StringArg(ArgsGroup * const g, const std::string & our_long_name, - const char our_short_name, const std::string & our_description) : + const char our_short_name, const std::string & our_description, + const bool can_be_negated) : ArgsOption(g, our_long_name, our_short_name, our_description), + _can_be_negated(can_be_negated), _validator(0) { } StringArg::StringArg(ArgsGroup * const g, const std::string & our_long_name, const char our_short_name, const std::string & our_description, - void (* v) (const std::string &)) : + void (* v) (const std::string &), const bool can_be_negated) : ArgsOption(g, our_long_name, our_short_name, our_description), + _can_be_negated(can_be_negated), _validator(v) { } @@ -567,7 +570,7 @@ AliasArg::can_be_negated() const bool StringArg::can_be_negated() const { - return false; + return _can_be_negated; } bool diff --git a/paludis/args/args_option.hh b/paludis/args/args_option.hh index 67db22fdc..1a35d6d06 100644 --- a/paludis/args/args_option.hh +++ b/paludis/args/args_option.hh @@ -219,6 +219,7 @@ namespace paludis { private: std::string _argument; + bool _can_be_negated; void (* _validator) (const std::string &); public: @@ -226,14 +227,16 @@ namespace paludis * Constructor */ StringArg(ArgsGroup * const, const std::string & long_name, - const char short_name, const std::string & description); + const char short_name, const std::string & description, + const bool can_be_negated = false); /** * Constructor with validator. */ StringArg(ArgsGroup * const, const std::string & long_name, const char short_name, const std::string & description, - void (* validator) (const std::string &)); + void (* validator) (const std::string &), + const bool can_be_negated = false); /** * Fetch the argument that was given to this option. diff --git a/paludis/args/args_visitor.cc b/paludis/args/args_visitor.cc index 700f047d3..af8ec032f 100644 --- a/paludis/args/args_visitor.cc +++ b/paludis/args/args_visitor.cc @@ -91,8 +91,14 @@ void ArgsVisitor::visit(StringArg & arg) if (! _imp->env_prefix.empty()) setenv(env_name(arg.long_name()).c_str(), p.c_str(), 1); } - else + else if (! arg.can_be_negated()) throw BadArgument("--no-" + arg.long_name()); + else + { + arg.set_specified(false); + if (! _imp->env_prefix.empty()) + unsetenv(env_name(arg.long_name()).c_str()); + } } void ArgsVisitor::visit(AliasArg & arg) |