aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2011-05-02 21:55:05 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2011-05-02 21:55:05 +0100
commitd22eca8b4565f8180c28d3b37618f3ea3a0b7f6e (patch)
treedaa9e6320814e1346072dbcebf77448818332699
parente48586fdc72b4c95df114a9ba1ccecae4418ef7b (diff)
downloadpaludis-d22eca8b4565f8180c28d3b37618f3ea3a0b7f6e.tar.gz
paludis-d22eca8b4565f8180c28d3b37618f3ea3a0b7f6e.tar.xz
Allow StringArgs to support --no-
-rw-r--r--paludis/args/args_option.cc9
-rw-r--r--paludis/args/args_option.hh7
-rw-r--r--paludis/args/args_visitor.cc8
3 files changed, 18 insertions, 6 deletions
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index 821669d..cecefa0 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 67db22f..1a35d6d 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 700f047..af8ec03 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)