From 5f06232d344ee0ee8a64558c613bde7b89b9054d Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 6 Feb 2023 17:54:20 +0300 Subject: [PATCH] [#44] cli: Support multiple configs Signed-off-by: Denis Kirillov --- cmd/frostfs-cli/modules/root.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/frostfs-cli/modules/root.go b/cmd/frostfs-cli/modules/root.go index a981f697..4bc317ba 100644 --- a/cmd/frostfs-cli/modules/root.go +++ b/cmd/frostfs-cli/modules/root.go @@ -19,6 +19,7 @@ import ( utilCli "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util" commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common" "github.com/TrueCloudLab/frostfs-node/misc" + "github.com/TrueCloudLab/frostfs-node/pkg/util/config" "github.com/TrueCloudLab/frostfs-node/pkg/util/gendoc" "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" @@ -32,6 +33,7 @@ const ( // Global scope flags. var ( cfgFile string + cfgDir string ) // rootCmd represents the base command when called without any subcommands. @@ -64,6 +66,7 @@ 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/frostfs-cli/config.yaml)") + rootCmd.PersistentFlags().StringVar(&cfgDir, "config-dir", "", "Config directory") rootCmd.PersistentFlags().BoolP(commonflags.Verbose, commonflags.VerboseShorthand, false, commonflags.VerboseUsage) @@ -121,4 +124,10 @@ func initConfig() { if err := viper.ReadInConfig(); err == nil { common.PrintVerbose(rootCmd, "Using config file: %s", viper.ConfigFileUsed()) } + + if cfgDir != "" { + if err := config.ReadConfigDir(viper.GetViper(), cfgDir); err != nil { + commonCmd.ExitOnErr(rootCmd, "failed to read config dir: %w", err) + } + } }