Begin a command error message with a custom string #1281
Labels
area/cobra-command
Core `cobra.Command` implementations
lifecycle/needs-pr
Ready for a PR from the community
It is a convention for CLI utilities in Unix-like environments to prefix the name of the utility to any error messages printed. For example, notice how the
find
command outputs thefind:
prefix:This is useful when debugging shell scripts for determining exactly which of the commands used in the script has failed.
Cobra has a convenient facility for declaring commands which might fail and return an error: the
Command.RunE()
method and friends. However, upon returning an error from such a method, we find that it is hard-coded inCommand.ExecuteC()
to prefix the stringError:
to any error message that results from this.My proposal is to add a way to change that hard-coded value to a custom string. Maybe use
argv[0]
by default to follow the convention. Without this feature, a programmer who wishes to adhere to the convention I mentioned is forced to implement their own error output inRun()
orRunE()
and/or silence the one provided by Cobra.The text was updated successfully, but these errors were encountered: