Skip to content

Treat arguments after -- as positionals in the arg parser - #1280

Open
0z5a wants to merge 1 commit into
meta:devfrom
0z5a:fix/arg-parser-end-of-options
Open

0z5a wants to merge 1 commit into
meta:devfrom
0z5a:fix/arg-parser-end-of-options

Conversation

@0z5a

@0z5a 0z5a commented Nov 14, 2026

Copy link
Copy Markdown

Summary

After --, ArgParser::parse jumps to the positional handling, but that code first checks the argument against the subcommand names and their one-letter aliases. As a result zli compress --profile serial -o c.zl -- c fails with "Trying to choose another subcommand 'compress' when one is already chosen (compress)". So there is no way to pass a file named c, d, t, train, compress, etc.

This change skips the subcommand matching after -- once a subcommand has been chosen, so the argument becomes a positional of that subcommand. The following still work as before:

  • Without --, a second subcommand name is still rejected.
  • zli -- compress ... still selects the subcommand, because none was chosen yet.

Type of Change

Bug fix (non-breaking change which fixes an issue)

Test Plan

  • New unit tests in tools/arg/tests/arg_parser_test.cpp:
    • SubcommandNameAfterEndOfOptionsIsPositional parses test -- t and test -- test. It fails on dev (the parser throws "Trying to choose another subcommand 'test' ...") and passes with the change.
    • SubcommandAfterEndOfOptions checks that -- test file still selects the subcommand.
  • test_arg_parser: 12/12 pass. cli_util_test: 11/11 pass. cli/tests/cli_integration_tests.py against the rebuilt zli: 24 tests OK.
  • Manual:
    • zli compress --profile serial -o c.zl -- c now works, and zli decompress -o c.out -- c.zl restores an identical file.
    • zli compress c -o c2.zl --profile serial (without --) still gives the same error as before.
  • clang-format --dry-run --Werror on both changed files: clean.

Test Configuration

  • Compiler: Apple clang (arm64)
  • Build type: RelWithDebInfo with -fsanitize=address,undefined
  • Platform(s): macOS 26

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

After "--", ArgParser::parse jumped to the positional handling, which
still compared the argument with the subcommand names and their
one-letter aliases. Files named c, d, train, etc. could therefore not
be passed to zli even after "--". Skip subcommand matching after "--"
once a subcommand has been chosen.
@meta-cla meta-cla Bot added the cla signed label Nov 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant