aboutsummaryrefslogtreecommitdiff
path: root/paludis/args
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/args')
-rw-r--r--paludis/args/args_dumper.cc9
-rw-r--r--paludis/args/args_dumper.hh3
-rw-r--r--paludis/args/args_option.cc49
-rw-r--r--paludis/args/args_option.hh45
-rw-r--r--paludis/args/args_visitor.cc19
-rw-r--r--paludis/args/args_visitor.hh9
-rw-r--r--paludis/args/man.cc4
7 files changed, 131 insertions, 7 deletions
diff --git a/paludis/args/args_dumper.cc b/paludis/args/args_dumper.cc
index ce142a1..d2b6d01 100644
--- a/paludis/args/args_dumper.cc
+++ b/paludis/args/args_dumper.cc
@@ -63,6 +63,11 @@ void ArgsDumper::visit(const StringSetArg & a)
}
}
+void ArgsDumper::visit(const StringSequenceArg & a)
+{
+ generic_visit(a);
+}
+
void ArgsDumper::visit(const EnumArg & a)
{
generic_visit(a);
@@ -103,7 +108,7 @@ ArgsDumper::visit(const IntegerArg & a)
void
ArgsDumper::visit(const AliasArg & a)
{
- if(!a.hidden())
- generic_visit(a);
+ if(! a.hidden())
+ generic_visit(a);
}
diff --git a/paludis/args/args_dumper.hh b/paludis/args/args_dumper.hh
index 078f82f..23cd164 100644
--- a/paludis/args/args_dumper.hh
+++ b/paludis/args/args_dumper.hh
@@ -81,6 +81,9 @@ namespace paludis
/// Visit a StringSetArg.
void visit(const StringSetArg &);
+
+ /// Visit a StringSequenceArg.
+ void visit(const StringSequenceArg &);
};
}
}
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index e3718a9..f373b41 100644
--- a/paludis/args/args_option.cc
+++ b/paludis/args/args_option.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -25,6 +25,7 @@
#include <set>
#include <vector>
#include <algorithm>
+#include <list>
using namespace paludis;
using namespace paludis::args;
@@ -34,6 +35,7 @@ template class WrappedForwardIterator<StringSetArg::AllowedArgConstIteratorTag,
const std::pair<std::string, std::string> >;
template class WrappedForwardIterator<EnumArg::AllowedArgConstIteratorTag,
const std::pair<std::string, std::string> >;
+template class WrappedForwardIterator<StringSequenceArg::ConstIteratorTag, const std::string>;
namespace
{
@@ -185,6 +187,45 @@ StringSetArg::add_argument(const std::string & arg)
_imp->args.insert(arg);
}
+namespace paludis
+{
+ template<>
+ struct Implementation<StringSequenceArg>
+ {
+ std::list<std::string> args;
+ };
+}
+
+StringSequenceArg::StringSequenceArg(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),
+ PrivateImplementationPattern<StringSequenceArg>(new Implementation<StringSequenceArg>)
+{
+}
+
+StringSequenceArg::~StringSequenceArg()
+{
+}
+
+StringSequenceArg::ConstIterator
+StringSequenceArg::begin_args() const
+{
+ return ConstIterator(_imp->args.begin());
+}
+
+StringSequenceArg::ConstIterator
+StringSequenceArg::end_args() const
+{
+ return ConstIterator(_imp->args.end());
+}
+
+void
+StringSequenceArg::add_argument(const std::string & arg)
+{
+ Context context("When handling argument '" + arg + "' for '--" + long_name() + "':");
+ _imp->args.push_back(arg);
+}
+
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)
@@ -355,6 +396,12 @@ StringSetArg::can_be_negated() const
}
bool
+StringSequenceArg::can_be_negated() const
+{
+ return false;
+}
+
+bool
SwitchArg::can_be_negated() const
{
return _can_be_negated;
diff --git a/paludis/args/args_option.hh b/paludis/args/args_option.hh
index 1d4a8aa..caab1c9 100644
--- a/paludis/args/args_option.hh
+++ b/paludis/args/args_option.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh
* Copyright (c) 2006 Stephen Bennett
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -315,6 +315,49 @@ namespace paludis
virtual bool can_be_negated() const;
};
+ /**
+ * An option that takes a set of strings.
+ *
+ * \since 0.32
+ * \ingroup g_args
+ * \nosubgrouping
+ */
+ class PALUDIS_VISIBLE StringSequenceArg :
+ public ArgsOption,
+ public AcceptInterfaceVisitsThis<ArgsVisitorTypes, StringSequenceArg>,
+ private PrivateImplementationPattern<StringSequenceArg>
+ {
+ public:
+ ///\name Basic operations
+ ///\{
+
+ StringSequenceArg(ArgsGroup * const, const std::string & long_name,
+ const char short_name, const std::string & description);
+
+ ~StringSequenceArg();
+
+ ///\}
+
+ ///\name Iterate over our args.
+ ///\{
+
+ struct ConstIteratorTag;
+ typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
+
+ ConstIterator begin_args() const;
+
+ ConstIterator end_args() const;
+
+ ///\}
+
+ /**
+ * Add an argument to the set.
+ */
+ void add_argument(const std::string & arg);
+
+ virtual bool can_be_negated() const;
+ };
+
/**
* An AliasArg is an alias for another argument.
diff --git a/paludis/args/args_visitor.cc b/paludis/args/args_visitor.cc
index b4af7ce..24e6097 100644
--- a/paludis/args/args_visitor.cc
+++ b/paludis/args/args_visitor.cc
@@ -1,6 +1,6 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -169,6 +169,23 @@ void ArgsVisitor::visit(StringSetArg & arg)
throw BadArgument("--no-" + arg.long_name());
}
+void ArgsVisitor::visit(StringSequenceArg & arg)
+{
+ if (! _no)
+ {
+ arg.set_specified(true);
+
+ std::string param = get_param(arg);
+ arg.add_argument(param);
+
+ if (! _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());
+}
+
std::string
ArgsVisitor::env_name(const std::string & long_name) const
{
diff --git a/paludis/args/args_visitor.hh b/paludis/args/args_visitor.hh
index 1fcf70e..5d554d1 100644
--- a/paludis/args/args_visitor.hh
+++ b/paludis/args/args_visitor.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh
* Copyright (c) 2006 Stephen Bennett
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -47,6 +47,7 @@ namespace paludis
class IntegerArg;
class EnumArg;
class StringSetArg;
+ class StringSequenceArg;
/**
* Visitor types for visitors that can visit Args.
@@ -62,7 +63,8 @@ namespace paludis
SwitchArg,
IntegerArg,
EnumArg,
- StringSetArg>
+ StringSetArg,
+ StringSequenceArg>
{
};
@@ -113,6 +115,9 @@ namespace paludis
/// Visit a StringSetArg.
void visit(StringSetArg &);
+ /// Visit a StringSequenceArg.
+ void visit(StringSequenceArg &);
+
/// Change whether we're visiting a --no- option
void set_no(const bool);
};
diff --git a/paludis/args/man.cc b/paludis/args/man.cc
index b6c21d2..4e2b3c2 100644
--- a/paludis/args/man.cc
+++ b/paludis/args/man.cc
@@ -88,6 +88,10 @@ namespace
_dw.end_extra_arg();
}
+
+ void visit(const StringSequenceArg &)
+ {
+ }
};
}