Repository navigation
fix(cli): keep the --help hint on an unknown command - #45
Merged
Merged
Conversation
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.
Fixes a regression I introduced in v0.21.1.
What broke
v0.21.1 stopped every error printing twice by setting
SilenceErrorson the root command and havingmainprint the error instead. Cobra writes the unknown-command hint from the same branch as the error line:Both lines are gated on
SilenceErrorsalone, not onSilenceUsage. Silencing the duplicate silenced the hint with it, andmainonly reproduced the error line.The
Did you mean this?suggestions were never affected; they are part oferr.Error().The fix
Cobra reports the error again and
mainonly turns a failure into an exit code.SilenceErrorsis removed from both root builders andrunloses its writer parameter.The reason v0.21.1 routed the print through
mainwas to keep the error below the background update notice. That does not hold up:CheckInBackgroundis called fromPersistentPreRun, which never runs when argument parsing fails, soWaitForUpdateCheckis nil on exactly these paths.printUpdateNoticeruns insidePersistentPreRun, before the command body, so the notice is already above any command output.Output now matches v0.21.0 minus the duplicate:
Tests
TestRunKeepsTheUnknownCommandHintwas written first and failed on the missing hint while already asserting the error appeared once, so it pins both halves and cannot be satisfied by reverting v0.21.1.The three existing tests carry over unchanged apart from the signature.
TestRunPrefixesTheErrorstill passes because cobra'sErrPrefix()isError:.Verification
go vetclean;gofmtclean on the touched files;make docsno diff.frobnicate,quer,dowload,sumarise,query --no-such-flag,columns --show nopeeach print the error once, exit 1, and unknown commands carry the hint.--help,columnsbyte-identical to the published v0.21.1 binary on both streams;versiondiffers only in the version string and Go toolchain, as expected for a local build.