Repository navigation
Add native_exact argparse policy and variadic positionals - #74
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the generic scan controls native Zig CLIs need from
argparse, without tool-specific workarounds. Based onmainafter #73.zero_or_more,one_or_more) for intermixed positionals,PositionalSpec.ignore_empty, andUnknownMode.positional.Policy.native_exactwithNegativeNumberMode.any,OptionSpec.allow_emptyandallow_dash_value, plusPolicy.flag_explicit_as_unknown,Policy.unknown_before_required,Policy.fail_fast,SpecialActionMode.prescanandCommandSpec.mutually_exclusive.ErrorKindonUsageErrorcovering all ten failure kinds, including.mutually_exclusive. Unrecognized-token payloads slice into the message, soUsageError.deinitis unchanged and the tests are leak-free.parse_intermixed_argsand a reference parser fornative_exact.Tested on Zig 0.17.1 and Python 3.14.10: per-commit
zig fmt --checkandzig build, 209/209 unit tests at the tip, docs build, and all 30 Python parity tests with no skips.