diff --git a/cmd/config.go b/cmd/config.go index 9e3eeff..d37b824 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -23,8 +23,21 @@ var ( DefaultConfig = Config{ userAgent: initUserAgent(), } + globalConfig *Config = NewConfig() ) +func NewConfig() *Config { + c := new(Config) + c.userAgent = initUserAgent() + c.Debug = false + c.OutputFormat = "simple" + return c +} + +func GetConfig() *Config { + return globalConfig +} + // Validate configuration struct func (c *Config) Validate() error { var err error @@ -69,7 +82,7 @@ func (c *Config) MergeWithEnv() { func LoadConfig(s string) (*Config, error) { var err error - var c *Config = &Config{} + var c *Config = GetConfig() *c = DefaultConfig @@ -83,7 +96,7 @@ func LoadConfig(s string) (*Config, error) { func LoadConfigFile(configPath string) (*Config, error) { var err error - var c *Config = &Config{} + var c *Config = GetConfig() *c = DefaultConfig diff --git a/cmd/main.go b/cmd/main.go index a188237..cfce3be 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -27,7 +27,7 @@ var BuildDate string var GitCommit string func Main(args []string) (int, error) { - var config *Config + var config *Config = GetConfig() var err error var i int