mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-24 03:31:21 +00:00
Fixed up the --home flag, ebuchman check this out
This commit is contained in:
parent
d05b8131a3
commit
ef3b9610a1
@ -24,7 +24,8 @@ const (
|
||||
func PrepareBaseCmd(cmd *cobra.Command, envPrefix, defautRoot string) func() {
|
||||
cobra.OnInitialize(func() { initEnv(envPrefix) })
|
||||
cmd.PersistentFlags().StringP(RootFlag, "r", defautRoot, "DEPRECATED. Use --home")
|
||||
cmd.PersistentFlags().StringP(HomeFlag, "h", defautRoot, "root directory for config and data")
|
||||
// -h is already reserved for --help as part of the cobra framework
|
||||
cmd.PersistentFlags().String(HomeFlag, "", "root directory for config and data")
|
||||
cmd.PersistentPreRunE = concatCobraCmdFuncs(bindFlagsLoadViper, cmd.PersistentPreRunE)
|
||||
return func() { execute(cmd) }
|
||||
}
|
||||
@ -104,7 +105,10 @@ func bindFlagsLoadViper(cmd *cobra.Command, args []string) error {
|
||||
// rootDir is command line flag, env variable, or default $HOME/.tlc
|
||||
// NOTE: we support both --root and --home for now, but eventually only --home
|
||||
rootDir := viper.GetString(HomeFlag)
|
||||
if !viper.IsSet(HomeFlag) && viper.IsSet(RootFlag) {
|
||||
// @ebuchman: viper.IsSet doesn't do what you think...
|
||||
// Even a default of "" on the pflag marks it as set,
|
||||
// simply by fact of having a pflag.
|
||||
if rootDir == "" {
|
||||
rootDir = viper.GetString(RootFlag)
|
||||
}
|
||||
viper.SetConfigName("config") // name of config file (without extension)
|
||||
|
@ -103,6 +103,9 @@ func TestSetupConfig(t *testing.T) {
|
||||
{nil, map[string]string{"RD_BOO": "bang"}, "bang"},
|
||||
{nil, map[string]string{"RD_ROOT": conf1}, cval1},
|
||||
{nil, map[string]string{"RDROOT": conf2}, cval2},
|
||||
{nil, map[string]string{"RDHOME": conf1}, cval1},
|
||||
// and when both are set??? HOME wins every time!
|
||||
{[]string{"--root", conf1}, map[string]string{"RDHOME": conf2}, cval2},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
|
Loading…
x
Reference in New Issue
Block a user