From 679c922e0c23bb6d21da4d1731a23e79d1a304b0 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 28 Jan 2022 21:03:44 +0300 Subject: [PATCH] [#1120] cli: Fix printing config file in `verbose` mode It was broken since `initConfig` was made before every execution of the command and flags have not been read by cobra yet, so it was impossible to print config file path if `verbose` flag was set in command line not in config file. Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/accounting.go | 2 -- cmd/neofs-cli/modules/control.go | 1 - cmd/neofs-cli/modules/root.go | 6 +++--- cmd/neofs-cli/modules/util.go | 2 -- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/neofs-cli/modules/accounting.go b/cmd/neofs-cli/modules/accounting.go index 0d4ec15d0..a5dc6d009 100644 --- a/cmd/neofs-cli/modules/accounting.go +++ b/cmd/neofs-cli/modules/accounting.go @@ -27,7 +27,6 @@ var accountingCmd = &cobra.Command{ _ = viper.BindPFlag(walletPath, flags.Lookup(walletPath)) _ = viper.BindPFlag(address, flags.Lookup(address)) _ = viper.BindPFlag(rpc, flags.Lookup(rpc)) - _ = viper.BindPFlag(verbose, flags.Lookup(verbose)) }, } @@ -67,7 +66,6 @@ func initAccountingBalanceCmd() { ff.StringP(walletPath, walletPathShorthand, walletPathDefault, walletPathUsage) ff.StringP(address, addressShorthand, addressDefault, addressUsage) ff.StringP(rpc, rpcShorthand, rpcDefault, rpcUsage) - ff.BoolP(verbose, verboseShorthand, verboseDefault, verboseUsage) accountingBalanceCmd.Flags().StringVar(&balanceOwner, "owner", "", "owner of balance account (omit to use owner from private key)") } diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index c91368569..65d9af509 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -27,7 +27,6 @@ var controlCmd = &cobra.Command{ _ = viper.BindPFlag(walletPath, ff.Lookup(walletPath)) _ = viper.BindPFlag(address, ff.Lookup(address)) _ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC)) - _ = viper.BindPFlag(verbose, ff.Lookup(verbose)) }, } diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index fed23d573..3b7b81299 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -117,6 +117,9 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.config/neofs-cli/config.yaml)") + rootCmd.PersistentFlags().BoolP(verbose, verboseShorthand, verboseDefault, verboseUsage) + + _ = viper.BindPFlag(verbose, rootCmd.PersistentFlags().Lookup(verbose)) // Cobra also supports local flags, which will only run // when this action is called directly. @@ -409,7 +412,6 @@ func parseXHeaders() []*session.XHeader { // - WIF; // - address; // - RPC; -// - verbose; func initCommonFlags(cmd *cobra.Command) { ff := cmd.Flags() @@ -417,7 +419,6 @@ func initCommonFlags(cmd *cobra.Command) { ff.StringP(walletPath, walletPathShorthand, walletPathDefault, walletPathUsage) ff.StringP(address, addressShorthand, addressDefault, addressUsage) ff.StringP(rpc, rpcShorthand, rpcDefault, rpcUsage) - ff.BoolP(verbose, verboseShorthand, verboseDefault, verboseUsage) } // bind common command flags to the viper @@ -428,7 +429,6 @@ func bindCommonFlags(cmd *cobra.Command) { _ = viper.BindPFlag(walletPath, ff.Lookup(walletPath)) _ = viper.BindPFlag(address, ff.Lookup(address)) _ = viper.BindPFlag(rpc, ff.Lookup(rpc)) - _ = viper.BindPFlag(verbose, ff.Lookup(verbose)) } func bindAPIFlags(cmd *cobra.Command) { diff --git a/cmd/neofs-cli/modules/util.go b/cmd/neofs-cli/modules/util.go index f88a05795..5e017d3b9 100644 --- a/cmd/neofs-cli/modules/util.go +++ b/cmd/neofs-cli/modules/util.go @@ -35,7 +35,6 @@ var ( _ = viper.BindPFlag(generateKey, flags.Lookup(generateKey)) _ = viper.BindPFlag(walletPath, flags.Lookup(walletPath)) _ = viper.BindPFlag(address, flags.Lookup(address)) - _ = viper.BindPFlag(verbose, flags.Lookup(verbose)) }, } @@ -194,7 +193,6 @@ func initCommonFlagsWithoutRPC(cmd *cobra.Command) { flags.BoolP(generateKey, generateKeyShorthand, generateKeyDefault, generateKeyUsage) flags.StringP(walletPath, walletPathShorthand, walletPathDefault, walletPathUsage) flags.StringP(address, addressShorthand, addressDefault, addressUsage) - flags.BoolP(verbose, verboseShorthand, verboseDefault, verboseUsage) } func initUtilSignBearerCmd() {