From 2a7e233cdbd38bcbcf45e15a379bd91b4dea6e45 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 16 Feb 2022 21:22:42 +0100 Subject: [PATCH] only check on config if it is getting used --- cmd/root.go | 9 --------- internal/config.go | 7 ++++++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index dd21124..0a49060 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,10 +1,8 @@ package cmd import ( - "fmt" "os" "path/filepath" - "strings" "github.com/cupcakearmy/autorestic/internal" "github.com/cupcakearmy/autorestic/internal/colors" @@ -88,12 +86,5 @@ func initConfig() { cfgFileName := ".autorestic" viper.SetConfigName(cfgFileName) viper.AutomaticEnv() - if viper.ConfigFileUsed() == "" { - colors.Error.Println( - fmt.Sprintf( - "cannot find configuration file '%s.yml' or '%s.yaml' in config paths: ['%s']", - cfgFileName, cfgFileName, strings.Join(configPaths, "', '"))) - os.Exit(1) - } } } diff --git a/internal/config.go b/internal/config.go index e9acace..7ed54f1 100644 --- a/internal/config.go +++ b/internal/config.go @@ -63,7 +63,12 @@ func GetConfig() *Config { } } } else { - return + cfgFileName := ".autorestic" + colors.Error.Println( + fmt.Sprintf( + "cannot find configuration file '%s.yml' or '%s.yaml'.", + cfgFileName, cfgFileName)) + os.Exit(1) } var versionConfig interface{}