Don't print Cobra error and Usage when an Error occurs
dominikbraun opened this issue · comments
Dominik Braun commented
This is a good first issue for anyone who wants to get started with spf13/cobra.
The verless CLI is built using Cobra. In case an errors occurs, Cobra prints the error and the usage of the particular command, and verless prints the same error again:
$ verless create project --abc
Error: unknown flag: --abc
Usage:
verless create project NAME [flags]
Flags:
-h, --help help for project
--overwrite overwrite the directory if it already exists
❌ unknown flag: --abc
Error: unknown flag: --abc
is the error message printed by Cobra.Usage: ...
is the command usage printed by Cobra.❌ unknown flag: --abc
is the error message printed by verless.
We only want to print the error message from verless.
For this purpose, Cobra offers two fields in the Command
type:
SilenceErrors
to prevent that errors are printedSilenceUsage
to prevent that the usage is printed
This fields must be set to true
for the root command, which is this one:
Lines 10 to 17 in 4bec8a4
That's it! The output should look like so:
$ verless create project --abc
❌ unknown flag: --abc
Pankhudi Bhonsle commented
I would like to work on this