Skip to content

Commit

Permalink
Correct order of preferences loading. Added more logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Feb 14, 2019
1 parent 4705594 commit 6145d74
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions commands/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (

"golang.org/x/crypto/ssh/terminal"

"github.com/mattn/go-colorable"
colorable "github.com/mattn/go-colorable"

"github.com/arduino/go-paths-helper"
paths "github.com/arduino/go-paths-helper"

"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/board"
Expand Down Expand Up @@ -118,11 +118,15 @@ func preRun(cmd *cobra.Command, args []string) {
// initConfigs initializes the configuration from the specified file.
func initConfigs() {
// Return error if an old configuration file is found
if paths.New(".cli-config.yml").Exist() {
logrus.Error("Old configuration file detected. Ensure you are using the new `arduino-cli.yaml` configuration")
formatter.PrintError(fmt.Errorf("old configuration file detected"), "Ensure you are using the new `arduino-cli.yaml` configuration")
if old := paths.New(".cli-config.yml"); old.Exist() {
logrus.Errorf("Old configuration file detected: %s.", old)
logrus.Info("The name of this file has been changed to `arduino-cli.yaml`, please rename the file fix it.")
formatter.PrintError(
fmt.Errorf("old configuration file detected: %s", old),
"The name of this file has been changed to `arduino-cli.yaml`, please rename the file fix it.")
os.Exit(commands.ErrGeneric)
}

// Start with default configuration
if conf, err := configs.NewConfiguration(); err != nil {
logrus.WithError(err).Error("Error creating default configuration")
Expand All @@ -138,18 +142,14 @@ func initConfigs() {
logrus.WithError(err).Warn("Did not manage to find current path")
}

commands.Config.Navigate("/", pwd)
commands.Config.LoadFromYAML(commands.Config.ConfigFile)

if yamlConfigFile != "" {
commands.Config.ConfigFile = paths.New(yamlConfigFile)
// Read configuration from global config file
if commands.Config.ConfigFile.Exist() {
logrus.Infof("Reading configuration from %s", commands.Config.ConfigFile)
if err := commands.Config.LoadFromYAML(commands.Config.ConfigFile); err != nil {
logrus.WithError(err).Warn("Did not manage to get config file, using default configuration")
logrus.WithError(err).Warnf("Could not read configuration from %s", commands.Config.ConfigFile)
}
}

logrus.Info("Initiating configuration")

if commands.Config.IsBundledInDesktopIDE() {
logrus.Info("CLI is bundled into the IDE")
err := commands.Config.LoadFromDesktopIDEPreferences()
Expand All @@ -159,6 +159,21 @@ func initConfigs() {
} else {
logrus.Info("CLI is not bundled into the IDE")
}

// Read configuration from parent folders (project config)
commands.Config.Navigate("/", pwd)

// Read configuration from environment vars
commands.Config.LoadFromEnv()

// Read configuration from user specified file
if yamlConfigFile != "" {
commands.Config.ConfigFile = paths.New(yamlConfigFile)
logrus.Infof("Reading configuration from %s", commands.Config.ConfigFile)
if err := commands.Config.LoadFromYAML(commands.Config.ConfigFile); err != nil {
logrus.WithError(err).Warnf("Could not read configuration from %s", commands.Config.ConfigFile)
}
}

logrus.Info("Configuration set")
}

0 comments on commit 6145d74

Please sign in to comment.