Skip to content

Commit ebb0de9

Browse files
committed
Refactored duplicated code
1 parent de5ac23 commit ebb0de9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

commands/root/root.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ func initConfigs() {
137137

138138
// Read configuration from global config file
139139
if commands.Config.ConfigFile.Exist() {
140-
logrus.Infof("Reading configuration from %s", commands.Config.ConfigFile)
141-
if err := commands.Config.LoadFromYAML(commands.Config.ConfigFile); err != nil {
142-
logrus.WithError(err).Warnf("Could not read configuration from %s", commands.Config.ConfigFile)
143-
}
140+
readConfigFrom(commands.Config.ConfigFile)
144141
}
145142

146143
if commands.Config.IsBundledInDesktopIDE() {
@@ -166,11 +163,15 @@ func initConfigs() {
166163
// Read configuration from user specified file
167164
if yamlConfigFile != "" {
168165
commands.Config.ConfigFile = paths.New(yamlConfigFile)
169-
logrus.Infof("Reading configuration from %s", commands.Config.ConfigFile)
170-
if err := commands.Config.LoadFromYAML(commands.Config.ConfigFile); err != nil {
171-
logrus.WithError(err).Warnf("Could not read configuration from %s", commands.Config.ConfigFile)
172-
}
166+
readConfigFrom(commands.Config.ConfigFile)
173167
}
174168

175169
logrus.Info("Configuration set")
176170
}
171+
172+
func readConfigFrom(path *paths.Path) {
173+
logrus.Infof("Reading configuration from %s", path)
174+
if err := commands.Config.LoadFromYAML(path); err != nil {
175+
logrus.WithError(err).Warnf("Could not read configuration from %s", path)
176+
}
177+
}

0 commit comments

Comments
 (0)