aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-01-04 00:56:42 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-01-04 00:56:42 +0000
commita1a15548d4c4e123910b4f3e892d47ebd4f91eed (patch)
tree9d6222c3ed7641e7cb2cee9ca39c3883ead131a7
parent9885b121b9ac42f5f9bb47d93c53698387999a79 (diff)
downloadpaludis-a1a15548d4c4e123910b4f3e892d47ebd4f91eed.tar.gz
paludis-a1a15548d4c4e123910b4f3e892d47ebd4f91eed.tar.xz
Change AliasArg so that it's a bit nicer with StringArg
-rw-r--r--paludis/args/args_TEST.cc12
-rw-r--r--paludis/args/args_option.cc8
-rw-r--r--paludis/args/args_option.hh5
-rw-r--r--paludis/args/args_visitor.cc2
4 files changed, 19 insertions, 8 deletions
diff --git a/paludis/args/args_TEST.cc b/paludis/args/args_TEST.cc
index a2cf285..a0fe323 100644
--- a/paludis/args/args_TEST.cc
+++ b/paludis/args/args_TEST.cc
@@ -44,6 +44,8 @@ struct CommandLine : public ArgsHandler
SwitchArg arg_baz;
AliasArg arg_other_baz;
StringArg arg_something;
+ StringArg arg_monkey;
+ AliasArg arg_other_monkey;
IntegerArg arg_somenum;
EnumArg arg_enum;
@@ -80,6 +82,8 @@ CommandLine::CommandLine() :
arg_baz(&group_two, "baz", 'z', "Enable baz"),
arg_other_baz(&arg_baz, "other-baz"),
arg_something(&group_two, "something", 's', "Value of something"),
+ arg_monkey(&group_two, "monkey", 'm', "A monkey?"),
+ arg_other_monkey(&arg_monkey, "other-monkey"),
arg_somenum(&group_two, "num", 'n', "Some number"),
arg_enum(&group_two, "enum", 'e', "One of three", EnumArg::EnumArgOptions("one", "Option one")("two", "option two")("three", "option three"), "two"),
@@ -107,10 +111,10 @@ namespace test_cases
void run()
{
- const char * args[] = { "program-name", "--other-baz", "-fsne", "blah", "7", "three", "--", "--dummy",
- "one", "two" };
+ const char * args[] = { "program-name", "--other-monkey", "chimp", "--other-baz",
+ "-fsne", "blah", "7", "three", "--", "--dummy", "one", "two" };
CommandLine c1;
- c1.run(10, args);
+ c1.run(12, args);
TEST_CHECK(c1.arg_foo.specified());
TEST_CHECK(! c1.arg_bar.specified());
TEST_CHECK(c1.arg_baz.specified());
@@ -124,6 +128,8 @@ namespace test_cases
TEST_CHECK(! c1.arg_dummy.specified());
TEST_CHECK(! c1.arg_other_enum.specified());
TEST_CHECK(c1.arg_other_enum.argument() == "b");
+ TEST_CHECK(c1.arg_monkey.specified());
+ TEST_CHECK(c1.arg_monkey.argument() == "chimp");
TEST_CHECK_EQUAL(std::distance(c1.begin_parameters(), c1.end_parameters()), 3);
TEST_CHECK_EQUAL(*c1.begin_parameters(), "--dummy");
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index d257c21..9537b26 100644
--- a/paludis/args/args_option.cc
+++ b/paludis/args/args_option.cc
@@ -57,11 +57,11 @@ SwitchArg::~SwitchArg()
{
}
-AliasArg::AliasArg(ArgsOption * const other, const std::string & our_long_name) :
- ArgsOption(other->group(), our_long_name, '\0', "Alias for --" + other->long_name()),
- _other(other)
+AliasArg::AliasArg(ArgsOption * const o, const std::string & our_long_name) :
+ ArgsOption(o->group(), our_long_name, '\0', "Alias for --" + o->long_name()),
+ _other(o)
{
- other->group()->handler()->add_option(other, our_long_name);
+ o->group()->handler()->add_option(o, our_long_name);
}
StringArg::StringArg(ArgsGroup * const g, const std::string & our_long_name,
diff --git a/paludis/args/args_option.hh b/paludis/args/args_option.hh
index fedeb38..601a110 100644
--- a/paludis/args/args_option.hh
+++ b/paludis/args/args_option.hh
@@ -238,6 +238,11 @@ namespace paludis
{
_other->set_specified(value);
}
+
+ ArgsOption * other() const
+ {
+ return _other;
+ }
};
/**
diff --git a/paludis/args/args_visitor.cc b/paludis/args/args_visitor.cc
index e2b97a8..c510f8b 100644
--- a/paludis/args/args_visitor.cc
+++ b/paludis/args/args_visitor.cc
@@ -61,7 +61,7 @@ void ArgsVisitor::visit(StringArg * const arg)
void ArgsVisitor::visit(AliasArg * const arg)
{
- visit(static_cast<ArgsOption *>(arg));
+ arg->other()->accept(this);
}
void ArgsVisitor::visit(SwitchArg * const arg)