From 4e2cc19cb8749b207c3bf6a3d7044e60316455a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= Date: Fri, 10 Mar 2023 15:51:07 +0100 Subject: [PATCH] cmd: enable SilenceUsage and SilenceErrors This prevents the CLI from printing the usage every time an error happens. I think this is much more visually clear now. --- cmd/root.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index fbbf6eb..f72f706 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 { @@ -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) } }