Problem
arg_parse clears and mutates caller-owned output arrays while it parses. If parsing fails after some earlier options were accepted, the caller can observe partially mutated state even though the function returned usage status 2.
A local repro from the review pass showed an existing option map being cleared and verbose=1 being written before a later --unknown option failed.
Fix
Parse into local temporary arrays first, and only publish to the caller-owned options and positionals arrays after the entire parse succeeds. Add regression coverage for both unknown-option and missing-value failures.
Validation
- Focused
lib/bash/arg/tests/lib_arg.bats coverage
./tests/validate.sh
Problem
arg_parseclears and mutates caller-owned output arrays while it parses. If parsing fails after some earlier options were accepted, the caller can observe partially mutated state even though the function returned usage status2.A local repro from the review pass showed an existing option map being cleared and
verbose=1being written before a later--unknownoption failed.Fix
Parse into local temporary arrays first, and only publish to the caller-owned
optionsandpositionalsarrays after the entire parse succeeds. Add regression coverage for both unknown-option and missing-value failures.Validation
lib/bash/arg/tests/lib_arg.batscoverage./tests/validate.sh