Skip to content

Commit

Permalink
fix(cli): Do not initialise config file if path changed (#829)
Browse files Browse the repository at this point in the history
Approved-by: Antoine Cotten <antoine@unikraft.io>
  • Loading branch information
antoineco committed Sep 19, 2023
2 parents 2dbb3b0 + 788146a commit a73e160
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions internal/cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,13 @@ func WithDefaultConfigManager(cmd *cobra.Command) CliOption {
if err != nil {
return err
}
cfgm, err := config.NewConfigManager(
cfg,
config.WithFile[config.KraftKit](config.DefaultConfigFile(), true),
)
if err != nil {
return err
}

// Attribute all configuration flags and command-line argument values
cmd, args, err := cmd.Find(os.Args[1:])
if err != nil {
return err
}
if err := cmdfactory.AttributeFlags(cmd, cfgm.Config, args...); err != nil {
if err := cmdfactory.AttributeFlags(cmd, cfg, args...); err != nil {
return err
}

Expand All @@ -142,6 +135,7 @@ func WithDefaultConfigManager(cmd *cobra.Command) CliOption {
// If a flag specifies changing the config directory, we must
// re-instantiate the ConfigManager with the configuration from that
// directory.
var cfgm *config.ConfigManager[config.KraftKit]
if cpath := cfg.Paths.Config; cpath != "" && cpath != config.ConfigDir() {
cfgm, err = config.NewConfigManager(
cfg,
Expand All @@ -150,6 +144,14 @@ func WithDefaultConfigManager(cmd *cobra.Command) CliOption {
if err != nil {
return err
}
} else {
cfgm, err = config.NewConfigManager(
cfg,
config.WithFile[config.KraftKit](config.DefaultConfigFile(), true),
)
if err != nil {
return err
}
}

copts.ConfigManager = cfgm
Expand Down

0 comments on commit a73e160

Please sign in to comment.