Skip to content

Change the directory of the configuration files #140

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

Merged
merged 26 commits into from
Feb 15, 2019
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7112bc2
Change the directory of the configuration files
matteosuppo Jan 31, 2019
f5d7eae
Stub new function configs.Navigate
matteosuppo Feb 1, 2019
4a73a8e
Navigate returns the default configuration
matteosuppo Feb 11, 2019
74f9f6a
Search for config file in local directory
matteosuppo Feb 11, 2019
f785e1c
Inherit configuration from parent folders
matteosuppo Feb 11, 2019
4712662
Make Navigate a method of Configuration
matteosuppo Feb 11, 2019
da73a11
Use config.Navigate in command root
matteosuppo Feb 11, 2019
5e22ab2
Forgot deps
matteosuppo Feb 11, 2019
8f0150b
Fix bugs in tests
matteosuppo Feb 11, 2019
5f9cff0
Read default config file (in .arduino15)
matteosuppo Feb 13, 2019
8659dd2
Rename configuration file
matteosuppo Feb 13, 2019
f9bf3a8
Remove configdir
matteosuppo Feb 13, 2019
392f7cf
Consistent usage of paths helper
matteosuppo Feb 13, 2019
b2e6f47
Add license where missing
matteosuppo Feb 13, 2019
11be6bd
Don't show the default package index
matteosuppo Feb 13, 2019
930b89a
Make linter happy
matteosuppo Feb 13, 2019
2453397
Fix navigate tests
matteosuppo Feb 13, 2019
0173160
Return an error message when there's a old configuration file
matteosuppo Feb 13, 2019
4705594
Fix path of default config
matteosuppo Feb 13, 2019
6145d74
Correct order of preferences loading. Added more logging.
cmaglie Feb 14, 2019
3d25175
Updated go-paths-helper
cmaglie Feb 14, 2019
5c48c84
Correctly handle error when looking for configuration on parent folders
cmaglie Feb 14, 2019
66ce6f8
configs: Correctly override board manager additional urls
cmaglie Feb 14, 2019
de5ac23
UploadsTests: go back to previous working directory after test
cmaglie Feb 14, 2019
ebb0de9
Refactored duplicated code
cmaglie Feb 14, 2019
fc64888
configs: if cwd could not be determined try to open 'arduino-cli.yaml…
cmaglie Feb 14, 2019
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
Prev Previous commit
Next Next commit
Correct order of preferences loading. Added more logging.
  • Loading branch information
cmaglie committed Feb 14, 2019
commit 6145d7486465c4ecfac9f2739bdf705032b52687
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")
}