Skip to content

Commit

Permalink
project create cmd fix
Browse files Browse the repository at this point in the history
Signed-off-by: Rizul Gupta <mail2rizul@gmail.com>
  • Loading branch information
rizul2108 committed Jan 9, 2025
1 parent 8dd8abb commit 69a7e6d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 69a7e6d

Please sign in to comment.