Make command-line flag parsing robust to lookalike flags and bad values - #159
Merged
Conversation
`extract_flag!` matched flags with `startswith` and unconditionally indexed
the second element of an unbounded `split` on `=`, so:
- `--verbose-foo` threw a BoundsError instead of the friendly "Unknown test
options" message;
- a custom flag extending a builtin's name (e.g. `--listing` vs `--list`)
was captured by the builtin, also throwing a BoundsError;
- `--jobs2=3` was silently accepted as `--jobs=3`;
- a bare `--jobs` crashed with a MethodError when `Some(nothing)` hit the
`Some{Int}` field of `ParsedArgs`, and `--jobs=abc` leaked a raw
ArgumentError from `parse`;
- values containing `=` (e.g. `--format=key=value`) were truncated.
Match only the exact flag or `--flag=value`, split with `limit=2`, and turn
missing or unparseable values into clean error messages. Also reject values
passed to the boolean flags `--verbose`/`--quickfail`/`--list`, which
previously crashed with a MethodError during ParsedArgs construction.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
giordano
commented
Aug 8, 2026
Comment on lines
+766
to
+771
| # boolean flags don't take values | ||
| for (flag, val) in (("--verbose", verbose), ("--quickfail", quickfail), ("--list", list)) | ||
| if val isa Some && something(val) !== nothing | ||
| error("Option `$flag` does not take a value") | ||
| end | ||
| end |
Collaborator
Author
There was a problem hiding this comment.
I don't think it'd be a bad idea to accept things like --verbose={true,false}, but currently these flags don't accept any value and error badly anyway, at least this gives a nice and clear error message.
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.
No description provided.