Carry clap's suggestion into the json usage error - #11
Conversation
@zmofei's `37afc38` already carries clap's suggestion into the json error, so the implementation this branch opened with was a duplicate and is dropped. What is left is test coverage for three cases its own test does not reach. - **A misspelled flag.** `--usernam` answers `a similar argument exists: '--username'`, through the same path — and a flag is the likelier typo of the two. Nothing pinned that it worked. - **No suggestion at all.** `--zzz` gets no `fix` key rather than an empty one, which is the rule the other optional keys in this error follow. Worth a test because "absent, not empty" is the kind of thing a later refactor turns into `"fix": ""` without noticing. - **`text` unchanged.** Clap still prints its own rendering there, tip included. This is the one that earns its place: the argument for carrying the tip into `json` was that `text` already had it, so a change that quietly moved it *out* of `text` would undo the reasoning while leaving the json test green. 588 tests, fmt and clippy clean.
|
Reduced this to what is actually additive, because the substance already landed. @zmofei's What is left is three test cases
588 tests, fmt and clippy clean. The approval on this predates the reduction, so it is no longer approval of what it approved — the content is now strictly a subset plus three tests. Flagging rather than treating it as still valid. One thing I backed out, and it is yours to decideI had also capitalised the tip, because every other Your test asserts the exact lowercase string with |
f258332 to
83f8c1b
Compare
Raised while reviewing #8, and worth landing before 0.2.0 rather than after it.
What's wrong
Clap works out what was probably meant and renders it as its own paragraph:
messageis built from clap's first paragraph — deliberately, so a missing-argument error names the arguments that sit on its later lines — and the tip is in the next paragraph, sotake_whilestops one line short of it.Under
-o textthat costs nothing, because clap prints its whole rendering. Under-o json, onlymessagesurvived:{"code":"usage","message":"unrecognized subcommand 'forward-geocode'"}The one part that says what to do instead was gone — in the rendering scripts and agents read. The consumers least able to guess a new name were the ones told least.
Why now and not after the release
#8 renames nine commands with no aliases, so 0.2.0 is precisely the release where a pinned script breaks. A hint that ships in 0.2.1 arrives after the moment it existed for.
Verified against #8's branch, which is where the motivating cases live:
fixnow returnedmapbox geocoder forward-geocodeA similar subcommand exists: 'forward'mapbox static-images get-static-imageA similar subcommand exists: 'static'mapbox tilequery getA similar subcommand exists: 'tilesets'All three renames now hand back a machine-readable pointer to the command that replaced them.
It helps misspelled flags too, which is the other thing clap suggests about —
--usernamanswersA similar argument exists: '--username'.Choices
fix, which already means "why it failed, and what would make it work", rather than inventing a key.fixin this crate reads as a sentence.{"code":"usage","message":"unexpected argument '--zzz' found"}gains nothing.textis untouched: that path still hands the error to clap to print, tip included.Tests
Four, and I checked they fail for the right reason rather than trusting green. Reverting the change reddens the two that assert the new behaviour and leaves the two asserting the old behaviour green:
588 tests,
cargo fmt --checkandcargo clippy --locked --all-targetsclean.Changelog
Per Mofei, the release pipeline stays in
mapbox-cli-private, so the canonicalCHANGELOG.mdis the one at that repo's root. The entry for this goes there — I'll add it to mapbox-cli-private#146, which is already open and is exactly that file.