forked from TrueCloudLab/frostfs-node
[#44] cli: Support multiple configs
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
bed5a36235
commit
5f06232d34
1 changed files with 9 additions and 0 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
utilCli "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
utilCli "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
||||||
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
|
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
"github.com/TrueCloudLab/frostfs-node/misc"
|
"github.com/TrueCloudLab/frostfs-node/misc"
|
||||||
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/config"
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/util/gendoc"
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/gendoc"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -32,6 +33,7 @@ const (
|
||||||
// Global scope flags.
|
// Global scope flags.
|
||||||
var (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
|
cfgDir string
|
||||||
)
|
)
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands.
|
// rootCmd represents the base command when called without any subcommands.
|
||||||
|
@ -64,6 +66,7 @@ func init() {
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
// will be global for your application.
|
// will be global for your application.
|
||||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "Config file (default is $HOME/.config/frostfs-cli/config.yaml)")
|
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,
|
rootCmd.PersistentFlags().BoolP(commonflags.Verbose, commonflags.VerboseShorthand,
|
||||||
false, commonflags.VerboseUsage)
|
false, commonflags.VerboseUsage)
|
||||||
|
|
||||||
|
@ -121,4 +124,10 @@ func initConfig() {
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
if err := viper.ReadInConfig(); err == nil {
|
||||||
common.PrintVerbose(rootCmd, "Using config file: %s", viper.ConfigFileUsed())
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue