aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/args.cc2
-rw-r--r--src/libutil/args.hh5
2 files changed, 4 insertions, 3 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index df7e04087..0eed49454 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -146,7 +146,7 @@ bool Args::processArgs(const Strings & args, bool finish)
res = true;
}
- if (finish && !expectedArgs.empty())
+ if (finish && !expectedArgs.empty() && !expectedArgs.front().optional)
throw UsageError("more arguments are required");
return res;
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index aa11373d5..ef8a7953e 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -51,6 +51,7 @@ protected:
{
std::string label;
size_t arity; // 0 = any
+ bool optional;
std::function<void(Strings)> handler;
};
@@ -165,7 +166,7 @@ public:
/* Expect a string argument. */
void expectArg(const std::string & label, string * dest)
{
- expectedArgs.push_back(ExpectedArg{label, 1, [=](Strings ss) {
+ expectedArgs.push_back(ExpectedArg{label, 1, false, [=](Strings ss) {
*dest = ss.front();
}});
}
@@ -173,7 +174,7 @@ public:
/* Expect 0 or more arguments. */
void expectArgs(const std::string & label, Strings * dest)
{
- expectedArgs.push_back(ExpectedArg{label, 0, [=](Strings ss) {
+ expectedArgs.push_back(ExpectedArg{label, 0, false, [=](Strings ss) {
*dest = ss;
}});
}