Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin a command error message with a custom string #1281

Closed
ashpool37 opened this issue Nov 22, 2020 · 2 comments · Fixed by #2023
Closed

Begin a command error message with a custom string #1281

ashpool37 opened this issue Nov 22, 2020 · 2 comments · Fixed by #2023
Labels
area/cobra-command Core `cobra.Command` implementations lifecycle/needs-pr Ready for a PR from the community

Comments

@ashpool37
Copy link

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.

@marckhouzam
Copy link
Collaborator

Sounds like a good idea. But you'll have to keep the existing behavior as the default to remain backwards-compatible.

@github-actions
Copy link

This issue is being marked as stale due to a long period of inactivity

@johnSchnake johnSchnake added area/cobra-command Core `cobra.Command` implementations lifecycle/needs-pr Ready for a PR from the community labels Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cobra-command Core `cobra.Command` implementations lifecycle/needs-pr Ready for a PR from the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants