mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 13:58:05 -05:00
Flags have higher precedence than config values
This commit is contained in:
@@ -124,6 +124,8 @@ $ gspt
|
||||
## Command-line Parameters
|
||||
|
||||
```
|
||||
NOTE: Command-line flags take priority over config values.
|
||||
|
||||
Usage of ./gspt:
|
||||
-c string
|
||||
Specify The Directory to check for config.yml file. (default "$XDG_CONFIG_HOME/gspt")
|
||||
|
||||
@@ -41,6 +41,12 @@ func NewConfigS() *ConfigS {
|
||||
|
||||
func ReadConfig() {
|
||||
parseFlags()
|
||||
|
||||
// If config path is provided through command-line use that
|
||||
if Flags.ConfigPath != "" {
|
||||
UserConfigPath = Flags.ConfigPath
|
||||
}
|
||||
|
||||
if configErr != nil {
|
||||
utils.Print("RED", "Couldn't get $XDG_CONFIG!")
|
||||
panic(configErr)
|
||||
@@ -52,7 +58,7 @@ func ReadConfig() {
|
||||
}
|
||||
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(UserConfigPath)
|
||||
viper.AddConfigPath(utils.ExpandHomeDir(UserConfigPath))
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
utils.Print("RED", "Could Not Read Config file.\n")
|
||||
@@ -65,6 +71,17 @@ func ReadConfig() {
|
||||
Config.CacheDir = utils.ExpandHomeDir(Config.CacheDir)
|
||||
}
|
||||
|
||||
// Flags have precedence over config values
|
||||
useFlags := func() {
|
||||
if Flags.HideImage != false {
|
||||
Config.HideImage = Flags.HideImage
|
||||
}
|
||||
if Flags.RoundedCorners != false {
|
||||
Config.RoundedCorners = Flags.RoundedCorners
|
||||
}
|
||||
}
|
||||
useFlags()
|
||||
|
||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||
viper.Unmarshal(Config)
|
||||
expandHome()
|
||||
|
||||
@@ -4,12 +4,22 @@ import (
|
||||
"flag"
|
||||
)
|
||||
|
||||
var (
|
||||
Flags = &Flag{}
|
||||
)
|
||||
|
||||
type Flag struct {
|
||||
ConfigPath string
|
||||
HideImage bool
|
||||
RoundedCorners bool
|
||||
}
|
||||
|
||||
func parseFlags() {
|
||||
flag.StringVar(&UserConfigPath, "c", UserConfigPath,
|
||||
flag.StringVar(&Flags.ConfigPath, "c", UserConfigPath,
|
||||
"Specify The Directory to check for config.yml file.")
|
||||
flag.BoolVar(&Config.HideImage, "hide-image", Config.HideImage,
|
||||
flag.BoolVar(&Flags.HideImage, "hide-image", Config.HideImage,
|
||||
"Do not display the cover art image.")
|
||||
flag.BoolVar(&Config.RoundedCorners, "rounded-corners", Config.RoundedCorners,
|
||||
flag.BoolVar(&Flags.RoundedCorners, "rounded-corners", Config.RoundedCorners,
|
||||
"Enable Rounded Corners")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user