diff options
| author | Paul Buetow <paul@buetow.org> | 2021-09-26 16:42:47 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-10-02 12:26:36 +0300 |
| commit | fcaa94c7453efa0d74e330128c0f5c2cde8f11b3 (patch) | |
| tree | 1f686e5eeeb1b180cc14a3586f388f1a3492899c /internal/config/setup.go | |
| parent | fe3e68afd99d8ea246be52893730f987e138ec24 (diff) | |
refactor config reader - also looks in additional search paths for config file unless NONE is specified
Diffstat (limited to 'internal/config/setup.go')
| -rw-r--r-- | internal/config/setup.go | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/internal/config/setup.go b/internal/config/setup.go index 3c4bcc4..be8e867 100644 --- a/internal/config/setup.go +++ b/internal/config/setup.go @@ -1,11 +1,5 @@ package config -import ( - "os" -) - -const NoConfigFile string = "Don't read a config file - use defaults only" - // Setup the DTail configuration. func Setup(args *Args, additionalArgs []string) { initializer := configInitializer{ @@ -13,23 +7,11 @@ func Setup(args *Args, additionalArgs []string) { Server: newDefaultServerConfig(), Client: newDefaultClientConfig(), } - - if args.ConfigFile == "" { - // TODO: Search more paths for config file (e.g. in /etc and in ~/.config/... - args.ConfigFile = "./cfg/dtail.json" - } - - if args.ConfigFile != NoConfigFile { - if _, err := os.Stat(args.ConfigFile); !os.IsNotExist(err) { - initializer.parseConfig(args.ConfigFile) - } - } - - // Assign pointers to global variables, so that we can access the - // configuration from any place of the program. - Common = initializer.Common - Server = initializer.Server - Client = initializer.Client - - args.transform(additionalArgs) + initializer.parseConfig(args) + Client, Server, Common = args.transformConfig( + additionalArgs, + initializer.Client, + initializer.Server, + initializer.Common, + ) } |
