aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-02 21:01:20 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-02 21:01:20 +0100
commitf2792e0e32498fe3c2369c3becdb0078fc2b5ee9 (patch)
tree2020919506f0eae5879b1e4abc16752f97c605d8
parenta6ad0e77a27a9ac5a7a4143cef68ea752e8c2c8a (diff)
downloadpaludis-f2792e0e32498fe3c2369c3becdb0078fc2b5ee9.tar.gz
paludis-f2792e0e32498fe3c2369c3becdb0078fc2b5ee9.tar.xz
Let args forward themselves
-rw-r--r--paludis/args/args_option.cc60
-rw-r--r--paludis/args/args_option.hh24
2 files changed, 84 insertions, 0 deletions
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index 1b560c6..b7b16ef 100644
--- a/paludis/args/args_option.cc
+++ b/paludis/args/args_option.cc
@@ -22,6 +22,7 @@
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/join.hh>
#include <set>
#include <vector>
#include <algorithm>
@@ -94,6 +95,15 @@ SwitchArg::~SwitchArg()
{
}
+const std::string
+SwitchArg::forwardable_string() const
+{
+ if (specified())
+ return "--" + long_name();
+ else
+ return "";
+}
+
AliasArg::AliasArg(ArgsOption * const o, const std::string & our_long_name, bool is_hidden) :
ArgsOption(o->group(), our_long_name, '\0', "Alias for --" + o->long_name()),
_other(o), _hidden(is_hidden)
@@ -101,6 +111,11 @@ AliasArg::AliasArg(ArgsOption * const o, const std::string & our_long_name, bool
o->group()->section()->handler()->add_option(o, our_long_name);
}
+const std::string
+AliasArg::forwardable_string() const
+{
+}
+
StringArg::StringArg(ArgsGroup * const g, const std::string & our_long_name,
const char our_short_name, const std::string & our_description) :
ArgsOption(g, our_long_name, our_short_name, our_description),
@@ -116,6 +131,15 @@ StringArg::StringArg(ArgsGroup * const g, const std::string & our_long_name,
{
}
+const std::string
+StringArg::forwardable_string() const
+{
+ if (specified())
+ return "--" + long_name() + " " + argument();
+ else
+ return "";
+}
+
namespace paludis
{
template<>
@@ -182,6 +206,15 @@ StringSetArg::add_argument(const std::string & arg)
_imp->args.insert(arg);
}
+const std::string
+StringSetArg::forwardable_string() const
+{
+ if (specified())
+ return "--" + long_name() + " " + join(begin_args(), end_args(), " ");
+ else
+ return "";
+}
+
namespace paludis
{
template<>
@@ -221,12 +254,30 @@ StringSequenceArg::add_argument(const std::string & arg)
_imp->args.push_back(arg);
}
+const std::string
+StringSequenceArg::forwardable_string() const
+{
+ if (specified())
+ return "--" + long_name() + " " + join(begin_args(), end_args(), " ");
+ else
+ return "";
+}
+
IntegerArg::IntegerArg(ArgsGroup * const our_group, const std::string & our_long_name,
char our_short_name, const std::string & our_description) :
ArgsOption(our_group, our_long_name, our_short_name, our_description)
{
}
+const std::string
+IntegerArg::forwardable_string() const
+{
+ if (specified())
+ return "--" + long_name() + " " + stringify(argument());
+ else
+ return "";
+}
+
namespace paludis
{
template<>
@@ -375,6 +426,15 @@ EnumArg::end_allowed_args() const
return AllowedArgConstIterator(_imp->allowed_args.end());
}
+const std::string
+EnumArg::forwardable_string() const
+{
+ if (specified())
+ return "--" + long_name() + " " + argument();
+ else
+ return "";
+}
+
StringSetArg::~StringSetArg()
{
}
diff --git a/paludis/args/args_option.hh b/paludis/args/args_option.hh
index 42befb3..1dfdb88 100644
--- a/paludis/args/args_option.hh
+++ b/paludis/args/args_option.hh
@@ -146,6 +146,16 @@ namespace paludis
* Needs to match up with ArgsVisitor logic.
*/
virtual bool can_be_negated() const = 0;
+
+ /**
+ * Ourself as a forwardable string.
+ *
+ * For example, '--foo bar' or '--foo bar --foo baz' or '--foo', or
+ * if not specified, the empty string.
+ *
+ * \since 0.40
+ */
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
};
/**
@@ -173,6 +183,8 @@ namespace paludis
~SwitchArg();
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
/**
@@ -213,6 +225,8 @@ namespace paludis
void set_argument(const std::string & arg);
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
/**
@@ -315,6 +329,8 @@ namespace paludis
///\}
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
/**
@@ -358,6 +374,8 @@ namespace paludis
void add_argument(const std::string & arg);
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
@@ -409,6 +427,8 @@ namespace paludis
}
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
/**
@@ -440,6 +460,8 @@ namespace paludis
void set_argument(const int arg) { _argument = arg; }
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
/**
@@ -567,6 +589,8 @@ namespace paludis
///\}
virtual bool can_be_negated() const;
+
+ virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
}