cli: skip argv0 and actions when parsing CLI flags

This fixes a regression from #2454. In that PR, we added an error when
positional arguments are detected. I believe that's correct, but we
were silently relying on the previous behavior in the CLI commands.

This commit changes the CLI commands to use a new argsIterator function
that creates an iterator that skips the first argument (argv0). This is
the same behavior that the config parsing does and now uses this shared
logic.

This also makes it so the argsIterator ignores actions (`+things`)
and we document that we expect those to be handled earlier.
This commit is contained in:
Mitchell Hashimoto
2024-10-18 12:53:32 -07:00
parent 98a7573ed4
commit c90ed29341
11 changed files with 54 additions and 22 deletions

View File

@@ -52,7 +52,7 @@ pub fn run(alloc: Allocator) !u8 {
defer opts.deinit();
{
var iter = try std.process.argsWithAllocator(alloc);
var iter = try args.argsIterator(alloc);
defer iter.deinit();
try args.parse(Options, alloc, &opts, &iter);
}