aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/args.cc12
-rw-r--r--src/libutil/args.hh4
2 files changed, 14 insertions, 2 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index 9377fe4c0..75eb19d28 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -60,6 +60,7 @@ void Args::parseCmdline(const Strings & _cmdline)
verbosity = lvlError;
}
+ bool argsSeen = false;
for (auto pos = cmdline.begin(); pos != cmdline.end(); ) {
auto arg = *pos;
@@ -88,6 +89,10 @@ void Args::parseCmdline(const Strings & _cmdline)
throw UsageError("unrecognised flag '%1%'", arg);
}
else {
+ if (!argsSeen) {
+ argsSeen = true;
+ initialFlagsProcessed();
+ }
pos = rewriteArgs(cmdline, pos);
pendingArgs.push_back(*pos++);
if (processArgs(pendingArgs, false))
@@ -96,6 +101,9 @@ void Args::parseCmdline(const Strings & _cmdline)
}
processArgs(pendingArgs, true);
+
+ if (!argsSeen)
+ initialFlagsProcessed();
}
bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
@@ -298,8 +306,8 @@ Strings argvToStrings(int argc, char * * argv)
return args;
}
-MultiCommand::MultiCommand(const Commands & commands)
- : commands(commands)
+MultiCommand::MultiCommand(const Commands & commands_)
+ : commands(commands_)
{
expectArgs({
.label = "subcommand",
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index 88f068087..4721c21df 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -132,6 +132,10 @@ protected:
std::set<std::string> hiddenCategories;
+ /* Called after all command line flags before the first non-flag
+ argument (if any) have been processed. */
+ virtual void initialFlagsProcessed() {}
+
public:
void addFlag(Flag && flag);