From f39caea8f295daa551a6c0284941b28edd4a24ff Mon Sep 17 00:00:00 2001 From: Fredrik Hansson Date: Mon, 28 Aug 2017 09:50:42 +0200 Subject: [PATCH 1/2] added support for a system wide config file /etc/sift.conf --- options.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/options.go b/options.go index 60f3bdbd..61d23309 100644 --- a/options.go +++ b/options.go @@ -289,6 +289,12 @@ func (o *Options) loadConfigFile(configFilePath string, label string) { // if noConf is true, only a config file set via option --conf will be parsed. func (o *Options) LoadConfigs(noConf bool, configFileArg string) { if !noConf { + if runtime.GOOS != "windows" { + // load system wide config if file exists + if _, err := os.Stat("/etc/sift.conf"); err == nil { + o.loadConfigFile("/etc/sift.conf", "system config") + } + } // load config from global sift config if file exists if homedir := getHomeDir(); homedir != "" { configFilePath := filepath.Join(homedir, SiftConfigFile) From 8fa9ac7d8df319420cef42363e404be198e5c172 Mon Sep 17 00:00:00 2001 From: Fredrik Hansson Date: Mon, 28 Aug 2017 10:05:39 +0200 Subject: [PATCH 2/2] printg the system path with --printf-config and changed the wording from Global config path to User config path --- options.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/options.go b/options.go index 61d23309..de7a9518 100644 --- a/options.go +++ b/options.go @@ -299,7 +299,7 @@ func (o *Options) LoadConfigs(noConf bool, configFileArg string) { if homedir := getHomeDir(); homedir != "" { configFilePath := filepath.Join(homedir, SiftConfigFile) if _, err := os.Stat(configFilePath); err == nil { - o.loadConfigFile(configFilePath, "global config") + o.loadConfigFile(configFilePath, "user config") } } @@ -709,9 +709,13 @@ func (o *Options) checkCompatibility(patterns []string, targets []string) error // processConfigOptions processes the options --print-config and --write-config func (o *Options) processConfigOptions() error { if o.PrintConfig { + if runtime.GOOS != "windows" { + // load system wide config if file exists + fmt.Fprintf(os.Stderr, "System config file path: %s\n", "/etc/sift.conf") + } if homedir := getHomeDir(); homedir != "" { globalConfigFilePath := filepath.Join(homedir, SiftConfigFile) - fmt.Fprintf(os.Stderr, "Global config file path: %s\n", globalConfigFilePath) + fmt.Fprintf(os.Stderr, "User config file path: %s\n", globalConfigFilePath) } else { errorLogger.Println("could not detect user home directory.") }