Extract shared raw CLI hint scanner (#342)#364
Conversation
`locale_hint_from_args` and `diag_json_hint_from_args` each re-implemented the same raw argument grammar (`--` terminator, `--flag value`, `--flag=value`, last-occurrence-wins), so a change to one path could silently diverge from the other. Introduce a single lexical scanner, `scan_raw_hints`, that records the last value for requested value-taking flags and the presence of requested bare flags. Both hint functions now delegate to it; value interpretation (locale string, output-format mapping) stays at the call sites. The scanner preserves the original greedy semantics: a value flag consumes the following token even when it looks like a flag, and a missing value or `--` terminator stops the scan. Add focused edge-case tests: trailing valueless flags keep earlier values, terminators stop scanning without discarding state, value flags consume flag-like tokens, the last (even unrecognised) `--output-format` wins, and a bare `--diag-json` survives an unrecognised format value.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideRefactors CLI startup hint parsing by extracting a shared raw argument scanner for locale and diagnostic JSON detection, preserving existing behaviour while adding targeted edge-case tests to pin the new grammar. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary
Closes #342
locale_hint_from_argsanddiag_json_hint_from_argsinsrc/cli_l10n.rsduplicated the raw argument grammar (--terminator,--flag value,--flag=value, last-wins). This extracts a single lexical scanner so the locale and diagnostic-mode startup paths cannot diverge.Changes
src/cli_l10n.rs: addscan_raw_hints(args, value_flags, bare_flags) -> RawArgHintsplus smallscan_value_flags/consume_flag_valuehelpers (flattened to satisfy the nesting threshold). Both public hint functions now delegate to it; value interpretation stays at the call sites as the issue suggests.tests/cli_tests/locale.rs: five new edge-case tests — trailing valueless flag keeps the earlier value,--after a value flag stops scanning without discarding state, a value flag greedily consumes a flag-like token (--output-format --diag-json→None), the last--output-formatwins even when unrecognised, and a bare--diag-jsonsurvives an unrecognised format value.All existing locale/diag-json hint tests pass unchanged, pinning behavioural equivalence.
Validation
make check-fmt/make lint/make test— pass (37 suites)🤖 Generated with Claude Code
Summary by Sourcery
Extract a shared raw CLI argument scanner used by locale and diagnostic JSON hint detection to keep their startup parsing behavior consistent.
Enhancements:
Tests:
--terminators, value precedence, and interaction between output format and diag-json flags.