feat(cli): add configuration-file persistant flag
This commit is contained in:
parent
efb709d31b
commit
ea80957f90
|
@ -85,6 +85,9 @@ func init() {
|
|||
|
||||
rootCmd.AddCommand(initCmd)
|
||||
rootCmd.AddCommand(loadCmd)
|
||||
rootCmd.AddCommand(saveCmd)
|
||||
rootCmd.PersistentFlags().StringP("configuration-file", "c", "", "location of configuration file")
|
||||
viper.BindPFlag("configuration-file", rootCmd.PersistentFlags().Lookup("configuration-file"))
|
||||
|
||||
loadCmd.PersistentFlags().Bool("disable-files", false, "files will be ignored")
|
||||
loadCmd.PersistentFlags().Bool("disable-folders", false, "folders will be ignored")
|
||||
|
|
|
@ -3,6 +3,8 @@ package mapper
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -54,11 +56,19 @@ func InitConfig() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
if c := os.Getenv("CONFIG_MAPPER_CFG"); c != "" {
|
||||
viper.AddConfigPath(c)
|
||||
} else {
|
||||
viper.AddConfigPath(h)
|
||||
if c := viper.GetString("configuration-file"); c != "" {
|
||||
if strings.Contains(c, ".yml") {
|
||||
c = path.Dir(c)
|
||||
}
|
||||
viper.AddConfigPath(path.Dir(c))
|
||||
}
|
||||
if c := os.Getenv("CONFIG_MAPPER_CFG"); c != "" {
|
||||
if strings.Contains(c, ".yml") {
|
||||
c = path.Dir(c)
|
||||
}
|
||||
viper.AddConfigPath(c)
|
||||
}
|
||||
viper.AddConfigPath(h)
|
||||
|
||||
viper.SetConfigType("yml")
|
||||
viper.SetConfigName(".config-mapper")
|
||||
|
|
Reference in New Issue