aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/args.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-10-24 12:45:11 +0200
committerEelco Dolstra <edolstra@gmail.com>2017-10-24 12:58:34 +0200
commit0d59f1ca49c9f7f3b2edaadcf590360ec66a6257 (patch)
treea03d53d84fb61eb354e2634705d8a076f0c1c76d /src/libutil/args.cc
parent25f32625e2f2a3a1e1b3a3811da82f21c3a3b880 (diff)
nix: Respect -I, --arg, --argstr
Also, random cleanup to argument handling.
Diffstat (limited to 'src/libutil/args.cc')
-rw-r--r--src/libutil/args.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index d17a1e7a9..7af2a1bf7 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -100,7 +100,7 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
auto process = [&](const std::string & name, const Flag & flag) -> bool {
++pos;
- Strings args;
+ std::vector<std::string> args;
for (size_t n = 0 ; n < flag.arity; ++n) {
if (pos == end) {
if (flag.arity == ArityAny) break;
@@ -109,7 +109,7 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
}
args.push_back(*pos++);
}
- flag.handler(args);
+ flag.handler(std::move(args));
return true;
};
@@ -144,7 +144,9 @@ bool Args::processArgs(const Strings & args, bool finish)
if ((exp.arity == 0 && finish) ||
(exp.arity > 0 && args.size() == exp.arity))
{
- exp.handler(args);
+ std::vector<std::string> ss;
+ for (auto & s : args) ss.push_back(s);
+ exp.handler(std::move(ss));
expectedArgs.pop_front();
res = true;
}
@@ -155,13 +157,17 @@ bool Args::processArgs(const Strings & args, bool finish)
return res;
}
-void Args::mkHashTypeFlag(const std::string & name, HashType * ht)
+Args::FlagMaker & Args::FlagMaker::mkHashTypeFlag(HashType * ht)
{
- mkFlag1(0, name, "TYPE", "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')", [=](std::string s) {
+ arity(1);
+ label("type");
+ description("hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')");
+ handler([ht](std::string s) {
*ht = parseHashType(s);
if (*ht == htUnknown)
- throw UsageError(format("unknown hash type '%1%'") % s);
+ throw UsageError("unknown hash type '%1%'", s);
});
+ return *this;
}
Strings argvToStrings(int argc, char * * argv)