aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-07-29 17:35:27 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-13 14:49:06 +0100
commitd6e4e464eeef466e4851056efe4e964a8b9ee266 (patch)
tree717c17310dd87cbe8a3f2ae9d3bf6129174c926d
parent7f1155d0b5f33ce499760e15ec1edbf24a29448a (diff)
downloadpaludis-d6e4e464eeef466e4851056efe4e964a8b9ee266.tar.gz
paludis-d6e4e464eeef466e4851056efe4e964a8b9ee266.tar.xz
Let enum args have single letter alias
-rw-r--r--paludis/args/args_dumper.cc8
-rw-r--r--paludis/args/args_option.cc63
-rw-r--r--paludis/args/args_option.hh61
-rw-r--r--paludis/args/man.cc30
-rw-r--r--paludis/args/man.hh9
5 files changed, 121 insertions, 50 deletions
diff --git a/paludis/args/args_dumper.cc b/paludis/args/args_dumper.cc
index 82bc6ed..b8274c5 100644
--- a/paludis/args/args_dumper.cc
+++ b/paludis/args/args_dumper.cc
@@ -75,12 +75,14 @@ void ArgsDumper::visit(const EnumArg & a)
it != it_end; ++it)
{
std::stringstream p;
- p << " " << (*it).first;
+ p << " " << it->long_name();
+ if (it->short_name())
+ p << " (" << std::string(1, it->short_name()) << ")";
if (p.str().length() < 26)
p << std::string(26 - p.str().length(), ' ');
_os << p.str();
- _os << " " << (*it).second;
- if ((*it).first == a.default_arg())
+ _os << " " << it->description();
+ if (it->long_name() == a.default_arg())
_os << " (default)";
_os << std::endl;
}
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index d1ecb33..6df2dd2 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, 2008 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009 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
@@ -21,6 +21,7 @@
#include "args_error.hh"
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/make_named_values.hh>
#include <set>
#include <vector>
#include <algorithm>
@@ -33,27 +34,29 @@ template class WrappedForwardIterator<StringSetArg::ConstIteratorTag, const std:
template class WrappedForwardIterator<StringSetArg::AllowedArgConstIteratorTag,
const std::pair<std::string, std::string> >;
template class WrappedForwardIterator<EnumArg::AllowedArgConstIteratorTag,
- const std::pair<std::string, std::string> >;
+ const AllowedEnumArg>;
template class WrappedForwardIterator<StringSequenceArg::ConstIteratorTag, const std::string>;
namespace
{
struct ArgIs
{
- /// The argument.
const std::string arg;
- /// Constructor.
ArgIs(const std::string & a) :
arg(a)
{
}
- /// Comparator.
bool operator() (const std::pair<std::string, std::string> & p) const
{
return p.first == arg;
}
+
+ bool operator() (const AllowedEnumArg & p) const
+ {
+ return p.long_name() == arg || (p.short_name() && std::string(1, p.short_name()) == arg);
+ }
};
}
@@ -80,8 +83,8 @@ ArgsOption::remove()
_group->handler()->remove_option(_long_name, _short_name);
}
-SwitchArg::SwitchArg(ArgsGroup * const our_group, std::string our_long_name, char our_short_name,
- std::string our_description, const bool c) :
+SwitchArg::SwitchArg(ArgsGroup * const our_group, const std::string & our_long_name, char our_short_name,
+ const std::string & our_description, const bool c) :
ArgsOption(our_group, our_long_name, our_short_name, our_description),
_can_be_negated(c)
{
@@ -229,24 +232,24 @@ namespace paludis
template<>
struct Implementation<EnumArg>
{
- std::vector<std::pair<std::string, std::string> > allowed_args;
+ std::vector<AllowedEnumArg> allowed_args;
};
template<>
struct Implementation<EnumArg::EnumArgOptions>
{
- std::vector<std::pair<std::string, std::string> > options;
+ std::vector<AllowedEnumArg> options;
};
}
-StringSetArg::StringSetArgOptions::StringSetArgOptions(std::string opt, std::string desc) :
+StringSetArg::StringSetArgOptions::StringSetArgOptions(const std::string & opt, const std::string & desc) :
PrivateImplementationPattern<StringSetArgOptions>(new Implementation<StringSetArgOptions>)
{
_imp->options.push_back(std::make_pair(opt, desc));
}
StringSetArg::StringSetArgOptions &
-StringSetArg::StringSetArgOptions::operator() (std::string opt, std::string desc)
+StringSetArg::StringSetArgOptions::operator() (const std::string & opt, const std::string & desc)
{
_imp->options.push_back(std::make_pair(opt, desc));
return *this;
@@ -295,15 +298,45 @@ EnumArg::~EnumArg()
{
}
-EnumArg::EnumArgOptions::EnumArgOptions(std::string opt, std::string desc) :
+EnumArg::EnumArgOptions::EnumArgOptions(const std::string & opt, const std::string & desc) :
PrivateImplementationPattern<EnumArgOptions>(new Implementation<EnumArgOptions>)
{
- _imp->options.push_back(std::make_pair(opt, desc));
+ _imp->options.push_back(make_named_values<AllowedEnumArg>(
+ value_for<n::description>(desc),
+ value_for<n::long_name>(opt),
+ value_for<n::short_name>('\0')
+ ));
+}
+
+EnumArg::EnumArgOptions::EnumArgOptions(const std::string & opt, const char s, const std::string & desc) :
+ PrivateImplementationPattern<EnumArgOptions>(new Implementation<EnumArgOptions>)
+{
+ _imp->options.push_back(make_named_values<AllowedEnumArg>(
+ value_for<n::description>(desc),
+ value_for<n::long_name>(opt),
+ value_for<n::short_name>(s)
+ ));
}
-EnumArg::EnumArgOptions & EnumArg::EnumArgOptions::operator() (std::string opt, std::string desc)
+EnumArg::EnumArgOptions &
+EnumArg::EnumArgOptions::operator() (const std::string & opt, const std::string & desc)
{
- _imp->options.push_back(std::make_pair(opt, desc));
+ _imp->options.push_back(make_named_values<AllowedEnumArg>(
+ value_for<n::description>(desc),
+ value_for<n::long_name>(opt),
+ value_for<n::short_name>('\0')
+ ));
+ return *this;
+}
+
+EnumArg::EnumArgOptions &
+EnumArg::EnumArgOptions::operator() (const std::string & opt, const char s, const std::string & desc)
+{
+ _imp->options.push_back(make_named_values<AllowedEnumArg>(
+ value_for<n::description>(desc),
+ value_for<n::long_name>(opt),
+ value_for<n::short_name>(s)
+ ));
return *this;
}
diff --git a/paludis/args/args_option.hh b/paludis/args/args_option.hh
index 675e8c0..42befb3 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, 2008 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
* Copyright (c) 2006 Stephen Bennett
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -25,6 +25,7 @@
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
#include <paludis/util/type_list.hh>
+#include <paludis/util/named_value.hh>
/** \file
* Declarations for ArgsOption.
@@ -38,6 +39,13 @@
namespace paludis
{
+ namespace n
+ {
+ struct description;
+ struct long_name;
+ struct short_name;
+ }
+
namespace args
{
class ArgsGroup;
@@ -159,8 +167,8 @@ namespace paludis
*
* \since 0.26
*/
- SwitchArg(ArgsGroup * const group, std::string long_name, char short_name,
- std::string description, const bool can_be_negated);
+ SwitchArg(ArgsGroup * const group, const std::string & long_name, char short_name,
+ const std::string & description, const bool can_be_negated);
~SwitchArg();
@@ -197,12 +205,12 @@ namespace paludis
/**
* Fetch the argument that was given to this option.
*/
- const std::string& argument() const { return _argument; }
+ const std::string & argument() const { return _argument; }
/**
* Set the argument returned by argument().
*/
- void set_argument(const std::string& arg);
+ void set_argument(const std::string & arg);
virtual bool can_be_negated() const;
};
@@ -237,7 +245,7 @@ namespace paludis
/**
* Constructor
*/
- StringSetArgOptions(const std::string, const std::string);
+ StringSetArgOptions(const std::string &, const std::string &);
/**
* Blank constructor
@@ -257,7 +265,7 @@ namespace paludis
/**
* Adds another (option, description) pair.
*/
- StringSetArgOptions & operator() (const std::string, const std::string);
+ StringSetArgOptions & operator() (const std::string &, const std::string &);
};
///\name Basic operations
@@ -435,6 +443,21 @@ namespace paludis
};
/**
+ * An allowed argument for an EnumArg.
+ *
+ * \ingroup g_args
+ * \since 0.40
+ */
+ struct AllowedEnumArg
+ {
+ NamedValue<n::description, std::string> description;
+ NamedValue<n::long_name, std::string> long_name;
+
+ /// Might be '\0', for none.
+ NamedValue<n::short_name, char> short_name;
+ };
+
+ /**
* An option that takes one of a predefined set of string arguments.
*
* \ingroup g_args
@@ -465,7 +488,14 @@ namespace paludis
/**
* Constructor
*/
- EnumArgOptions(const std::string, const std::string);
+ EnumArgOptions(const std::string &, const std::string &);
+
+ /**
+ * Constructor, with short arg.
+ *
+ * \since 0.40
+ */
+ EnumArgOptions(const std::string &, const char, const std::string &);
/**
* Destructor.
@@ -473,9 +503,16 @@ namespace paludis
~EnumArgOptions();
/**
- * Adds another (option, description) pair.
+ * Adds another (option, description).
*/
- EnumArgOptions & operator() (const std::string, const std::string);
+ EnumArgOptions & operator() (const std::string &, const std::string &);
+
+ /**
+ * Adds another (option, short-option, description).
+ *
+ * \since 0.40
+ */
+ EnumArgOptions & operator() (const std::string &, const char, const std::string &);
};
/**
@@ -520,8 +557,8 @@ namespace paludis
///\{
struct AllowedArgConstIteratorTag;
- typedef WrappedForwardIterator<AllowedArgConstIteratorTag,
- const std::pair<std::string, std::string> > AllowedArgConstIterator;
+ typedef WrappedForwardIterator<AllowedArgConstIteratorTag,
+ const AllowedEnumArg> AllowedArgConstIterator;
AllowedArgConstIterator begin_allowed_args() const;
diff --git a/paludis/args/man.cc b/paludis/args/man.cc
index 433c21e..17ba90a 100644
--- a/paludis/args/man.cc
+++ b/paludis/args/man.cc
@@ -65,9 +65,7 @@ namespace
for (EnumArg::AllowedArgConstIterator a(e.begin_allowed_args()), a_end(e.end_allowed_args()) ;
a != a_end ; ++a)
- {
- _dw.extra_arg_enum(a->first, a->second, e.default_arg());
- }
+ _dw.extra_arg_enum(*a, e.default_arg());
_dw.end_extra_arg();
}
@@ -79,11 +77,9 @@ namespace
_dw.start_extra_arg();
- for (EnumArg::AllowedArgConstIterator a(e.begin_allowed_args()), a_end(e.end_allowed_args()) ;
+ for (StringSetArg::AllowedArgConstIterator a(e.begin_allowed_args()), a_end(e.end_allowed_args()) ;
a != a_end ; ++a)
- {
_dw.extra_arg_string_set(a->first, a->second);
- }
_dw.end_extra_arg();
}
@@ -241,14 +237,17 @@ HtmlWriter::start_extra_arg()
}
void
-HtmlWriter::extra_arg_enum(const std::string & first, const std::string & second, const std::string & default_arg)
+HtmlWriter::extra_arg_enum(const AllowedEnumArg & e, const std::string & default_arg)
{
std::string default_string;
- if (first == default_arg)
+ if (e.long_name() == default_arg)
default_string = " (default)";
- _os << "<dt>" << first << "</dt>" << endl;
- _os << "<dd>" << second << default_string << "</dd>" << endl;
+ _os << "<dt>" << e.long_name();
+ if (e.short_name())
+ _os << " (" << std::string(1, e.short_name()) << ")";
+ _os << "</dt>" << endl;
+ _os << "<dd>" << e.description() << default_string << "</dd>" << endl;
}
void
@@ -441,16 +440,19 @@ ManWriter::start_extra_arg()
}
void
-ManWriter::extra_arg_enum(const std::string & first, const std::string & second, const std::string & default_arg)
+ManWriter::extra_arg_enum(const AllowedEnumArg & e, const std::string & default_arg)
{
std::string default_string;
- if (first == default_arg)
+ if (e.long_name() == default_arg)
default_string = " (default)";
_os << ".RS" << endl;
_os << ".TP" << endl;
- _os << ".B \"" << first << "\"" << endl;
- _os << second << default_string << endl;
+ _os << ".B \"" << e.long_name();
+ if (e.short_name())
+ _os << " (" << std::string(1, e.short_name()) << ")";
+ _os << "\"" << endl;
+ _os << e.description() << default_string << endl;
_os << ".RE" << endl;
}
diff --git a/paludis/args/man.hh b/paludis/args/man.hh
index de593a6..dad2926 100644
--- a/paludis/args/man.hh
+++ b/paludis/args/man.hh
@@ -68,8 +68,7 @@ namespace paludis
virtual void arg_group_item(const char & short_name, const std::string & long_name,
const std::string & negated_long_name, const std::string & description) = 0;
virtual void start_extra_arg() = 0;
- virtual void extra_arg_enum(const std::string & first, const std::string & second,
- const std::string & default_arg) = 0;
+ virtual void extra_arg_enum(const AllowedEnumArg &, const std::string & default_arg) = 0;
virtual void extra_arg_string_set(const std::string & first, const std::string & second) = 0;
virtual void end_extra_arg() = 0;
virtual void end_arg_group() = 0;
@@ -128,8 +127,7 @@ namespace paludis
void arg_group_item(const char & short_name, const std::string & long_name,
const std::string & negated_long_name, const std::string & description);
void start_extra_arg();
- void extra_arg_enum(const std::string & first, const std::string & second,
- const std::string & default_arg);
+ void extra_arg_enum(const AllowedEnumArg &, const std::string & default_arg);
void extra_arg_string_set(const std::string & first, const std::string & second);
void end_extra_arg();
void end_arg_group();
@@ -186,8 +184,7 @@ namespace paludis
void arg_group_item(const char & short_name, const std::string & long_name,
const std::string & negated_long_name, const std::string & description);
void start_extra_arg();
- void extra_arg_enum(const std::string & first, const std::string & second,
- const std::string & default_arg);
+ void extra_arg_enum(const AllowedEnumArg &, const std::string & default_arg);
void extra_arg_string_set(const std::string & first, const std::string & second);
void end_extra_arg();
void end_arg_group();