Skip to content

Commit

Permalink
cmd: enable SilenceUsage and SilenceErrors
Browse files Browse the repository at this point in the history
This prevents the CLI from printing the usage every time an error
happens. I think this is much more visually clear now.
  • Loading branch information
chrboe committed Mar 10, 2023
1 parent e4ecbfd commit 4e2cc19
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ func rootCommand() *cobra.Command {
}

rootCmd := &cobra.Command{
Use: "linstor-gateway",
Version: version,
Short: "Manage linstor-gateway targets and exports",
Args: cobra.NoArgs,
Use: "linstor-gateway",
Version: version,
Short: "Manage linstor-gateway targets and exports",
Args: cobra.NoArgs,
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
level, err := log.ParseLevel(loglevel)
if err != nil {
Expand Down Expand Up @@ -118,7 +120,7 @@ func Execute() {
cobra.OnInitialize(initConfig)
rootCmd := rootCommand()
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
log.Error(err)
os.Exit(1)
}
}

0 comments on commit 4e2cc19

Please sign in to comment.