cli: stop dumping help on every error#334
Open
cpcloud wants to merge 1 commit into
Open
Conversation
roborev: Combined Review (
|
Cobra's default behavior dumps the full usage block on every RunE error, which buries actual error messages under a wall of help text. Four import commands had been working around this by scattering SilenceUsage: true on their cobra.Command structs, but every other RunE handler still printed the help wall on, e.g., a failed sync or a missing OAuth token. Centralize the policy: - Root PersistentPreRunE sets cmd.SilenceUsage = true at the top. Cobra runs flag parsing and Args validators before PersistentPreRunE, so unknown flags / bad arg counts still get usage. Everything reached via RunE runs with usage silenced. - usageErr(cmd, err) flips SilenceUsage back to false for RunE-internal invocation-contract errors (mutex flags, bad enums, missing required values, bad date/phone formats). Applied across syncfull, stats, search, import (whatsapp), export-attachment, deletions, delete-deduped, create-subset, add-imap, and add-account. - Drop the now-redundant SilenceUsage assignments from the four import_* commands. Resulting behavior: msgvault sync-full --bogus Error + usage (cobra default) msgvault sync-full --limit=-1 Error + usage (usageErr) msgvault sync-incremental missing@ Error only (runtime)
33c3f11 to
9b88169
Compare
roborev: Combined Review (
|
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.
Summary
Cobra's default behavior dumps the full usage block on every
RunEerror, which buries actual error messages under a wall of help text. Four import commands worked around this by scatteringSilenceUsage: trueon theircobra.Commandstructs, but every other RunE handler still printed the help wall on, e.g., a failed sync or a missing OAuth token.Mirrors the cleanup done in roborev (
roborev-dev/roborev#727).What changed
PersistentPreRunEsetscmd.SilenceUsage = trueat the top. Cobra runs flag parsing andArgsvalidators beforePersistentPreRunE, so unknown flags / bad arg counts still get usage. Anything reached viaRunEruns with usage silenced.usageErr(cmd, err)flipsSilenceUsageback tofalsefor RunE-internal invocation-contract errors (mutex flags, bad enums, missing required values, bad date/phone formats). Applied acrosssyncfull,stats,search,import(whatsapp),export-attachment,deletions,delete-deduped,create-subset,add-imap,add-account.SilenceUsageassignments from the fourimport_*commands.Resulting behavior
msgvault sync-full --bogusError: unknown flag: --bogus+ usage (cobra default)msgvault sync-full --limit=-1 ...Error: --limit must be a non-negative number+ usagemsgvault sync-incremental missing@...Error: ...no source found...only (no usage)