feat: env-var fallbacks and did-you-mean for unknown flags - #57
Merged
Merged
Conversation
… PARSE-12, HELP-3, ERR-3, ERR-4, ARGS-2 pending; TRUST-5) Co-authored-by: noah-emp <noah@emerging-patterns.com>
…ior unchanged Arg keeps eight fields; laws that named a default generalize over the env var beside it. The gate and the demo are unchanged. Co-authored-by: noah-emp <noah@emerging-patterns.com>
…p); prove SHAKE-PARSE-11, PARSE-12, HELP-3, ARGS-2 Co-authored-by: noah-emp <noah@emerging-patterns.com>
Co-authored-by: noah-emp <noah@emerging-patterns.com>
…'s tip in err_text; prove SHAKE-ERR-3, ERR-4 Co-authored-by: noah-emp <noah@emerging-patterns.com>
Co-authored-by: noah-emp <noah@emerging-patterns.com>
Co-authored-by: noah-emp <noah@emerging-patterns.com>
noah-emp
marked this pull request as ready for review
October 2, 2026 02:30
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 env-var fallbacks for options and a "did you mean" tip on unknown long flags.
parse's signature and behavior are unchanged.Design notes: docs/rfc/shake-env-and-suggestions.md.
Env-var fallbacks: CLI > env > default
parse_env(spec, words, vars)isparseagainst the spec with each argument's default replaced by its fallback. A value from the words always wins. Otherwise the env value is used, and failing that, the default.NAME= tooluses the default.0,false,no,off,norf.required(SHAKE-PARSE-7). A required positional filled this way doesn't block a subcommand (SHAKE-PARSE-4).parse_env(spec, words, [])isparse(spec, words), proved as lawenv_none. Arguments with no env var still follow SHAKE-PARSE-6.BadValue{at, name, value}. This applies only when the parse otherwise succeeds and that value is the one bound. The first such argument is reported, root command first, in spec order. Any other failure comes before it.[env: NAME]after the help text, before[default: ...]and[possible values: ...].env_vars(spec)asksIO.get_envfor every env var the spec names: the root's first, then subcommands depth first, each in spec order. It keeps the pairs that are set. The IO part is the one new Trusted assumption.Did-you-mean for
UnknownFlagsuggestion(spec, err)returns something only for anUnknownFlagwhose word starts with--.--, up to any=.at, reached the wayhelpreaches it. Parent commands' arguments, subcommands and--helpare not candidates.dfrom the typed spelling satisfies0 < dand3*d <= max(len(typed), len(c)). That distance counts insertions, deletions, substitutions and swaps of two adjacent chars.suggestionisSome{s},err_textcontainss. SHAKE-ERR-1 and ERR-2 still hold; the ERR-2 proof's message now includes the tip.Manual check with a compiled binary:
HI_NAME=bob hi --name=albindsal.HI_NAME=andHI_LOUD=offfall back to the default.HI_COLOR=greenfails withBadValue.hi gobinds the requiredwhofromHI_WHO.--nmae,--nam,--colr=red,--loduand--plianeach get the right tip.--zzz,--na,-z,--hepl, andgo --name(a parent's option) get none.