mirror of https://github.com/liamg/aminal.git
Fix -ignore-config flag behavior (#134)
* Fix the behavior of the -ignore-config command line flag * Fix the bug with determining which flags are actually provided in the command line
This commit is contained in:
parent
ab80fcd44e
commit
76f883032f
51
config.go
51
config.go
|
@ -11,24 +11,31 @@ import (
|
||||||
"github.com/liamg/aminal/version"
|
"github.com/liamg/aminal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getConfig() *config.Config {
|
func getActuallyProvidedFlags() map[string]bool {
|
||||||
|
result := make(map[string]bool)
|
||||||
|
|
||||||
showVersion := false
|
flag.Visit(func(f *flag.Flag) {
|
||||||
flag.BoolVar(&showVersion, "version", showVersion, "Output version information")
|
result[f.Name] = true
|
||||||
|
})
|
||||||
|
|
||||||
ignore := false
|
return result
|
||||||
flag.BoolVar(&ignore, "ignore-config", ignore, "Ignore user config files and use defaults")
|
|
||||||
if ignore {
|
|
||||||
return &config.DefaultConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := loadConfigFile()
|
func getConfig() *config.Config {
|
||||||
|
showVersion := false
|
||||||
|
ignoreConfig := false
|
||||||
|
shell := ""
|
||||||
|
debugMode := false
|
||||||
|
slomo := false
|
||||||
|
|
||||||
flag.StringVar(&conf.Shell, "shell", conf.Shell, "Specify the shell to use")
|
flag.BoolVar(&showVersion, "version", showVersion, "Output version information")
|
||||||
flag.BoolVar(&conf.DebugMode, "debug", conf.DebugMode, "Enable debug logging")
|
flag.BoolVar(&ignoreConfig, "ignore-config", ignoreConfig, "Ignore user config files and use defaults")
|
||||||
flag.BoolVar(&conf.Slomo, "slomo", conf.Slomo, "Render in slow motion (useful for debugging)")
|
flag.StringVar(&shell, "shell", shell, "Specify the shell to use")
|
||||||
|
flag.BoolVar(&debugMode, "debug", debugMode, "Enable debug logging")
|
||||||
|
flag.BoolVar(&slomo, "slomo", slomo, "Render in slow motion (useful for debugging)")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse() // actual parsing and fetching flags from the command line
|
||||||
|
actuallyProvidedFlags := getActuallyProvidedFlags()
|
||||||
|
|
||||||
if showVersion {
|
if showVersion {
|
||||||
v := version.Version
|
v := version.Version
|
||||||
|
@ -39,6 +46,26 @@ func getConfig() *config.Config {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var conf *config.Config
|
||||||
|
if ignoreConfig {
|
||||||
|
conf = &config.DefaultConfig
|
||||||
|
} else {
|
||||||
|
conf = loadConfigFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override values in the configuration file with the values specified in the command line, if any.
|
||||||
|
if actuallyProvidedFlags["shell"] {
|
||||||
|
conf.Shell = shell
|
||||||
|
}
|
||||||
|
|
||||||
|
if actuallyProvidedFlags["debug"] {
|
||||||
|
conf.DebugMode = debugMode
|
||||||
|
}
|
||||||
|
|
||||||
|
if actuallyProvidedFlags["slomo"] {
|
||||||
|
conf.Slomo = slomo
|
||||||
|
}
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue