Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Project create cmd fix #307

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions pkg/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,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 @@ -181,14 +181,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
Loading