From 69a7e6d68267aa3d9a00b23d3de37cc822338561 Mon Sep 17 00:00:00 2001 From: Rizul Gupta Date: Fri, 10 Jan 2025 00:29:32 +0530 Subject: [PATCH] project create cmd fix Signed-off-by: Rizul Gupta --- pkg/utils/config.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/utils/config.go b/pkg/utils/config.go index ec83542c..dc00258e 100644 --- a/pkg/utils/config.go +++ b/pkg/utils/config.go @@ -77,14 +77,14 @@ func InitConfig(cfgFile string, userSpecifiedConfig bool) { } // Read and unmarshal the config file - v, err := ReadConfig(harborConfigPath) + err = ReadConfig(harborConfigPath) if err != nil { configInitError = err log.Fatalf("%v", err) } var harborConfig HarborConfig - if err := v.Unmarshal(&harborConfig); err != nil { + if err := viper.Unmarshal(&harborConfig); err != nil { configInitError = fmt.Errorf("failed to unmarshal config file: %w", err) log.Fatalf("%v", configInitError) } @@ -168,14 +168,13 @@ func EnsureConfigFileExists(harborConfigPath string) error { } // Helper function to read the config file using Viper -func ReadConfig(harborConfigPath string) (*viper.Viper, error) { - v := viper.New() - v.SetConfigFile(harborConfigPath) - v.SetConfigType("yaml") - if err := v.ReadInConfig(); err != nil { - return nil, fmt.Errorf("error reading config file: %w. Please ensure the config file exists.", err) +func ReadConfig(harborConfigPath string) error { + viper.SetConfigFile(harborConfigPath) + viper.SetConfigType("yaml") + if err := viper.ReadInConfig(); err != nil { + return fmt.Errorf("error reading config file: %w. Please ensure the config file exists.", err) } - return v, nil + return nil } func GetCurrentHarborConfig() (*HarborConfig, error) {