mirror of
https://github.com/outbackdingo/ghorg.git
synced 2026-01-27 10:19:03 +00:00
Fix ghorg config env (#188)
This commit is contained in:
@@ -2,7 +2,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
|
||||
## [1.7.10] - unreleased
|
||||
### Added
|
||||
### Changed
|
||||
### Deprecated
|
||||
### Removed
|
||||
### Fixed
|
||||
Configuration env var; thanks @Rabattkarte
|
||||
### Security
|
||||
|
||||
## [1.7.9] - 2/27/22
|
||||
### Added
|
||||
|
||||
@@ -709,7 +709,7 @@ func PrintConfigs() {
|
||||
colorlog.PrintInfo("* Dry Run : " + "true")
|
||||
}
|
||||
|
||||
colorlog.PrintInfo("* Config Used : " + os.Getenv("GHORG_CONF"))
|
||||
colorlog.PrintInfo("* Config Used : " + os.Getenv("GHORG_CONFIG"))
|
||||
|
||||
colorlog.PrintInfo("*************************************")
|
||||
fmt.Println("")
|
||||
|
||||
12
cmd/root.go
12
cmd/root.go
@@ -128,21 +128,21 @@ func getOrSetDefaults(envVar string) {
|
||||
func InitConfig() {
|
||||
if config != "" {
|
||||
viper.SetConfigFile(config)
|
||||
os.Setenv("GHORG_CONF", config)
|
||||
os.Setenv("GHORG_CONFIG", config)
|
||||
} else {
|
||||
config = configs.DefaultConfFile()
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(configs.GhorgDir())
|
||||
viper.SetConfigName("conf")
|
||||
os.Setenv("GHORG_CONF", configs.DefaultConfFile())
|
||||
os.Setenv("GHORG_CONFIG", configs.DefaultConfFile())
|
||||
|
||||
}
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
os.Setenv("GHORG_CONF", "none")
|
||||
os.Setenv("GHORG_CONFIG", "none")
|
||||
} else {
|
||||
colorlog.PrintError(fmt.Sprintf("Something unexpected happened reading configuration file: %s, err: %s", os.Getenv("GHORG_CONF"), err))
|
||||
colorlog.PrintError(fmt.Sprintf("Something unexpected happened reading configuration file: %s, err: %s", os.Getenv("GHORG_CONFIG"), err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func InitConfig() {
|
||||
if os.Getenv("GHORG_DEBUG") != "" {
|
||||
viper.Debug()
|
||||
fmt.Println("Viper config file used:", viper.ConfigFileUsed())
|
||||
fmt.Printf("GHORG_CONF SET TO: %s\n", os.Getenv("GHORG_CONF"))
|
||||
fmt.Printf("GHORG_CONFIG SET TO: %s\n", os.Getenv("GHORG_CONFIG"))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func init() {
|
||||
cobra.OnInitialize(InitConfig)
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&color, "color", "", "GHORG_COLOR - toggles colorful output, enabled/disabled (default: disabled)")
|
||||
rootCmd.PersistentFlags().StringVar(&config, "config", "", "manually set the path to your config file")
|
||||
rootCmd.PersistentFlags().StringVar(&config, "config", "", "GHORG_CONFIG - manually set the path to your config file")
|
||||
|
||||
viper.SetDefault("config", configs.DefaultConfFile())
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ var versionCmd = &cobra.Command{
|
||||
Short: "Print the version number of Ghorg",
|
||||
Long: `All software has versions. This is Ghorg's`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("v1.7.9")
|
||||
fmt.Println("v1.7.10")
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user