Skip to content

Add native_exact argparse policy and variadic positionals - #74

Merged
HaoZeke merged 4 commits into
mainfrom
feat/argparse-native-exact
Nov 20, 2026
Merged

HaoZeke merged 4 commits into
mainfrom
feat/argparse-native-exact

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Adds the generic scan controls native Zig CLIs need from argparse, without tool-specific workarounds. Based on main after #73.

  • Variadic positional arities (zero_or_more, one_or_more) for intermixed positionals, PositionalSpec.ignore_empty, and UnknownMode.positional.
  • Policy.native_exact with NegativeNumberMode.any, OptionSpec.allow_empty and allow_dash_value, plus Policy.flag_explicit_as_unknown, Policy.unknown_before_required, Policy.fail_fast, SpecialActionMode.prescan and CommandSpec.mutually_exclusive.
  • A structured ErrorKind on UsageError covering all ten failure kinds, including .mutually_exclusive. Unrecognized-token payloads slice into the message, so UsageError.deinit is unchanged and the tests are leak-free.
  • Differential fuzz tests against Python 3.14 parse_intermixed_args and a reference parser for native_exact.

Tested on Zig 0.17.1 and Python 3.14.10: per-commit zig fmt --check and zig build, 209/209 unit tests at the tip, docs build, and all 30 Python parity tests with no skips.

Add PositionalArity.zero_or_more and PositionalArity.one_or_more for
intermixed variadic positionals alongside PositionalSpec.ignore_empty
for skipping empty positional tokens while a slot is unfilled. Add
UnknownMode.positional so unrecognized option-like tokens flow into
declared positional slots while preserving overflow checks.
Add Policy.native_exact with NegativeNumberMode.any so value options can
consume dash-prefixed tokens while OptionSpec.allow_empty and
OptionSpec.allow_dash_value enforce per-option value rules.

Add Policy.flag_explicit_as_unknown and Policy.unknown_before_required
plus Policy.fail_fast so exact native parsers report scan-time errors
left-to-right instead of deferring unrecognized tokens. Add
SpecialActionMode.prescan to handle help or version ahead of option
scanning and CommandSpec.mutually_exclusive for conflicting option
groups.
Add an exhaustive ErrorKind tagged union on UsageError so native CLI
callers can render tool-specific single-line diagnostics directly from
the classified failure instead of parsing UsageError.message.

Unrecognized token payloads slice directly into UsageError.message
rather than adding a second heap allocation, keeping UsageError.deinit
unchanged and leak-free under std.testing.allocator.
Extend tests/argparse_parity_probe.zig and tests/test_argparse_parity.py
with differential fuzz tests for intermixed variadic positionals against
Python 3.14 parse_intermixed_args and for Policy.native_exact against a
reference parser covering SpecialActionMode.prescan plus
PositionalSpec.ignore_empty alongside CommandSpec.mutually_exclusive and
UnknownMode.positional with ErrorKind.
@HaoZeke
HaoZeke merged commit fdbe824 into main Nov 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant