-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
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 the find:
prefix:
$ find nemo
find: ‘nemo’: No such file or directory
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 in Command.ExecuteC()
to prefix the string Error:
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 in Run()
or RunE()
and/or silence the one provided by Cobra.