aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2011-10-04 22:15:40 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2011-10-04 22:19:54 +0100
commita415d9a3a6065927d64719b803d7f9b40ec0b55d (patch)
tree3172fd4e580515ff9a5b593438bea74c9e940b83
parent338d0ebd6a158fedb3763c2d8f028646a73978af (diff)
downloadpaludis-a415d9a3a6065927d64719b803d7f9b40ec0b55d.tar.gz
paludis-a415d9a3a6065927d64719b803d7f9b40ec0b55d.tar.xz
Refactor checking for --no- validity
-rw-r--r--paludis/args/args_handler.cc2
-rw-r--r--paludis/args/args_visitor.cc120
2 files changed, 50 insertions, 72 deletions
diff --git a/paludis/args/args_handler.cc b/paludis/args/args_handler.cc
index 3ebe998..afb3966 100644
--- a/paludis/args/args_handler.cc
+++ b/paludis/args/args_handler.cc
@@ -232,6 +232,8 @@ ArgsHandler::run(
it = _imp->longopts.find(arg);
if (it == _imp->longopts.end())
throw BadArgument("--no-" + arg);
+ if (! it->second->can_be_negated())
+ throw BadArgument("--no-" + arg);
std::string remaining_chars;
ArgsVisitor visitor(&argit, arge, env_prefix, remaining_chars, true, specifiedness);
diff --git a/paludis/args/args_visitor.cc b/paludis/args/args_visitor.cc
index d39cccb..76b5336 100644
--- a/paludis/args/args_visitor.cc
+++ b/paludis/args/args_visitor.cc
@@ -99,8 +99,6 @@ void ArgsVisitor::visit(StringArg & arg)
if (! _imp->env_prefix.empty())
setenv(env_name(arg.long_name()).c_str(), p.c_str(), 1);
}
- else if (! arg.can_be_negated())
- throw BadArgument("--no-" + arg.long_name());
else
{
arg.set_specified(aos_not);
@@ -122,8 +120,6 @@ void ArgsVisitor::visit(SwitchArg & arg)
if (! _imp->env_prefix.empty())
setenv(env_name(arg.long_name()).c_str(), "1", 1);
}
- else if (! arg.can_be_negated())
- throw BadArgument("--no-" + arg.long_name());
else
{
arg.set_specified(aos_not);
@@ -134,99 +130,79 @@ void ArgsVisitor::visit(SwitchArg & arg)
void ArgsVisitor::visit(IntegerArg & arg)
{
- if (! _imp->no)
- {
- if (arg.explicitly_specified())
- Log::get_instance()->message("args.specified_twice", ll_warning, lc_context)
- << "Option '--" << arg.long_name() << "' was specified more than once, but it does not take multiple values";
+ if (arg.explicitly_specified())
+ Log::get_instance()->message("args.specified_twice", ll_warning, lc_context)
+ << "Option '--" << arg.long_name() << "' was specified more than once, but it does not take multiple values";
- arg.set_specified(_imp->specifiedness);
- std::string param;
+ arg.set_specified(_imp->specifiedness);
+ std::string param;
- if ((! _imp->remaining_chars.empty()) && (std::string::npos == _imp->remaining_chars.find_first_not_of("0123456789")))
- {
- param = _imp->remaining_chars;
- _imp->remaining_chars.clear();
- }
- else
- param = get_param(arg);
+ if ((! _imp->remaining_chars.empty()) && (std::string::npos == _imp->remaining_chars.find_first_not_of("0123456789")))
+ {
+ param = _imp->remaining_chars;
+ _imp->remaining_chars.clear();
+ }
+ else
+ param = get_param(arg);
- try
- {
- int a(destringify<int>(param));
- arg.set_argument(a);
+ try
+ {
+ int a(destringify<int>(param));
+ arg.set_argument(a);
- if (! _imp->env_prefix.empty())
- setenv(env_name(arg.long_name()).c_str(), stringify(a).c_str(), 1);
- }
- catch (const DestringifyError &)
- {
- throw BadValue("--" + arg.long_name(), param);
- }
+ if (! _imp->env_prefix.empty())
+ setenv(env_name(arg.long_name()).c_str(), stringify(a).c_str(), 1);
+ }
+ catch (const DestringifyError &)
+ {
+ throw BadValue("--" + arg.long_name(), param);
}
- else
- throw BadArgument("--no-" + arg.long_name());
}
void ArgsVisitor::visit(EnumArg & arg)
{
- if (! _imp->no)
- {
- if (arg.explicitly_specified())
- Log::get_instance()->message("args.specified_twice", ll_warning, lc_context)
- << "Option '--" << arg.long_name() << "' was specified more than once, but it does not take multiple values";
-
- arg.set_specified(_imp->specifiedness);
+ if (arg.explicitly_specified())
+ Log::get_instance()->message("args.specified_twice", ll_warning, lc_context)
+ << "Option '--" << arg.long_name() << "' was specified more than once, but it does not take multiple values";
- std::string p;
- if (_imp->remaining_chars.length() == 1)
- {
- p = _imp->remaining_chars;
- _imp->remaining_chars.clear();
- }
- else
- p = get_param(arg);
+ arg.set_specified(_imp->specifiedness);
- arg.set_argument(p);
- if (! _imp->env_prefix.empty())
- setenv(env_name(arg.long_name()).c_str(), p.c_str(), 1);
+ std::string p;
+ if (_imp->remaining_chars.length() == 1)
+ {
+ p = _imp->remaining_chars;
+ _imp->remaining_chars.clear();
}
else
- throw BadArgument("--no-" + arg.long_name());
+ p = get_param(arg);
+
+ arg.set_argument(p);
+ if (! _imp->env_prefix.empty())
+ setenv(env_name(arg.long_name()).c_str(), p.c_str(), 1);
}
void ArgsVisitor::visit(StringSetArg & arg)
{
- if (! _imp->no)
- {
- arg.set_specified(_imp->specifiedness);
+ arg.set_specified(_imp->specifiedness);
- std::string param = get_param(arg);
- arg.add_argument(param);
+ std::string param = get_param(arg);
+ arg.add_argument(param);
- if (! _imp->env_prefix.empty())
- setenv(env_name(arg.long_name()).c_str(), join(arg.begin_args(),
- arg.end_args(), " ").c_str(), 1);
- }
- else
- throw BadArgument("--no-" + arg.long_name());
+ if (! _imp->env_prefix.empty())
+ setenv(env_name(arg.long_name()).c_str(), join(arg.begin_args(),
+ arg.end_args(), " ").c_str(), 1);
}
void ArgsVisitor::visit(StringSequenceArg & arg)
{
- if (! _imp->no)
- {
- arg.set_specified(_imp->specifiedness);
+ arg.set_specified(_imp->specifiedness);
- std::string param = get_param(arg);
- arg.add_argument(param);
+ std::string param = get_param(arg);
+ arg.add_argument(param);
- if (! _imp->env_prefix.empty())
- setenv(env_name(arg.long_name()).c_str(), join(arg.begin_args(),
- arg.end_args(), " ").c_str(), 1);
- }
- else
- throw BadArgument("--no-" + arg.long_name());
+ if (! _imp->env_prefix.empty())
+ setenv(env_name(arg.long_name()).c_str(), join(arg.begin_args(),
+ arg.end_args(), " ").c_str(), 1);
}
std::string