Skip to content

Commit f11373b

Browse files
committed
Merge tag '0.3.6-alpha.preview' into daemon
Release 0.3.6-alpha.preview
2 parents 37cc5ed + fac2419 commit f11373b

File tree

31 files changed

+2595
-92
lines changed

31 files changed

+2595
-92
lines changed

.cli-config_example.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/main
44
/.vscode/settings.json
55
/cmd/formatter/debug.test
6-
/.cli-config.yml
6+
/arduino-cli.yaml
77
/wiki

Gopkg.lock

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This is **not yet available** until the first stable version is released.
1717
#### Download the latest unstable "alpha" preview
1818

1919
Please note that these are **preview** build, they may have bugs, some features may not work or may be changed without notice,
20-
the latest preview version is `0.3.4-alpha.preview`:
20+
the latest preview version is `0.3.6-alpha.preview`:
2121

2222
- [Linux 64 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli-latest-linux64.tar.bz2)
2323
- [Linux 32 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli-latest-linux32.tar.bz2)
@@ -26,7 +26,7 @@ the latest preview version is `0.3.4-alpha.preview`:
2626
- [Windows](https://downloads.arduino.cc/arduino-cli/arduino-cli-latest-windows.zip)
2727
- [Mac OSX](https://downloads.arduino.cc/arduino-cli/arduino-cli-latest-osx.zip)
2828

29-
Once downloaded, place the executable into a directory which is in your `PATH` environment variable. To use the tool as it is presented in the Getting started guide below (`arduino-cli`), you should rename the executable from _arduino-cli-0.2.2-alpha.preview-XYZ_ to _arduino-cli_.
29+
Once downloaded, place the executable into a directory which is in your `PATH` environment variable. To use the tool as it is presented in the Getting started guide below (`arduino-cli`), you should rename the executable from _arduino-cli-X.Y.Z-alpha.preview-XYZ_ to _arduino-cli_.
3030

3131
### Build the latest "bleeding-edge" from source
3232

@@ -165,7 +165,7 @@ and the Board Name look good, we are ready to compile and upload the sketch
165165

166166
#### Adding 3rd party cores
167167

168-
To add 3rd party core packages add a link of the additional package to the file `.cli-config.yml`
168+
To add 3rd party core packages add a link of the additional package to the file `arduino-cli.yaml`
169169

170170
If you want to add the ESP8266 core, for example:
171171

@@ -174,9 +174,9 @@ If you want to add the ESP8266 core, for example:
174174
- http://arduino.esp8266.com/stable/package_esp8266com_index.json
175175

176176
And then run:
177-
178-
arduino-cli core update-index
179-
arduino-cli core install esp8266:esp8266
177+
178+
arduino-cli core update-index
179+
arduino-cli core install esp8266:esp8266
180180

181181
### Step 5. Compile the sketch
182182

@@ -303,7 +303,7 @@ Flags:
303303
-h, --help help for core
304304

305305
Global Flags:
306-
--config-file string The custom config file (if not specified ./.cli-config.yml will be used). (default "/home/megabug/Workspace/go/src/github.com/arduino/arduino-cli/.cli-config.yml")
306+
--config-file string The custom config file (if not specified the default one will be used).
307307
--debug Enables debug output (super verbose, used to debug the CLI).
308308
--format string The output format, can be [text|json]. (default "text")
309309

cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const (
4949
)
5050

5151
// Version is the current CLI version
52-
var Version = "0.3.4-alpha.preview"
52+
var Version = "0.3.6-alpha.preview"
5353

5454
// ErrLogrus represents the logrus instance, which has the role to
5555
// log all non info messages.

cli/cli_test.go

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ func executeWithArgs(t *testing.T, args ...string) (int, []byte) {
7474

7575
// This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method
7676
func() {
77+
// Create an empty config for the CLI test
78+
conf := paths.New("arduino-cli.yaml")
79+
require.False(t, conf.Exist())
80+
err := conf.WriteFile([]byte("board_manager:\n additional_urls:\n"))
81+
require.NoError(t, err)
82+
defer func() {
83+
require.NoError(t, conf.Remove())
84+
}()
85+
7786
redirect := &stdOutRedirect{}
7887
redirect.Open(t)
7988
defer func() {
@@ -512,27 +521,33 @@ func TestCompileCommands(t *testing.T) {
512521
require.True(t, paths.New(test1).Join("Test1.arduino.avr.nano.hex").Exist())
513522

514523
// Build sketch with --output path
515-
require.NoError(t, os.Chdir(tmp))
516-
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", "test", test1)
517-
require.Zero(t, exitCode, "exit code")
518-
require.Contains(t, string(d), "Sketch uses")
519-
require.True(t, paths.New("test.hex").Exist())
520-
521-
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", "test2.hex", test1)
522-
require.Zero(t, exitCode, "exit code")
523-
require.Contains(t, string(d), "Sketch uses")
524-
require.True(t, paths.New("test2.hex").Exist())
525-
require.NoError(t, paths.New(tmp, "anothertest").MkdirAll())
526-
527-
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", "anothertest/test", test1)
528-
require.Zero(t, exitCode, "exit code")
529-
require.Contains(t, string(d), "Sketch uses")
530-
require.True(t, paths.New("anothertest", "test.hex").Exist())
531-
532-
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", tmp+"/anothertest/test2", test1)
533-
require.Zero(t, exitCode, "exit code")
534-
require.Contains(t, string(d), "Sketch uses")
535-
require.True(t, paths.New("anothertest", "test2.hex").Exist())
524+
{
525+
pwd, err := os.Getwd()
526+
require.NoError(t, err)
527+
defer func() { require.NoError(t, os.Chdir(pwd)) }()
528+
require.NoError(t, os.Chdir(tmp))
529+
530+
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", "test", test1)
531+
require.Zero(t, exitCode, "exit code")
532+
require.Contains(t, string(d), "Sketch uses")
533+
require.True(t, paths.New("test.hex").Exist())
534+
535+
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", "test2.hex", test1)
536+
require.Zero(t, exitCode, "exit code")
537+
require.Contains(t, string(d), "Sketch uses")
538+
require.True(t, paths.New("test2.hex").Exist())
539+
require.NoError(t, paths.New(tmp, "anothertest").MkdirAll())
540+
541+
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", "anothertest/test", test1)
542+
require.Zero(t, exitCode, "exit code")
543+
require.Contains(t, string(d), "Sketch uses")
544+
require.True(t, paths.New("anothertest", "test.hex").Exist())
545+
546+
exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", "-o", tmp+"/anothertest/test2", test1)
547+
require.Zero(t, exitCode, "exit code")
548+
require.Contains(t, string(d), "Sketch uses")
549+
require.True(t, paths.New("anothertest", "test2.hex").Exist())
550+
}
536551
}
537552

538553
func TestInvalidCoreURL(t *testing.T) {
@@ -544,7 +559,7 @@ func TestInvalidCoreURL(t *testing.T) {
544559
require.NoError(t, err, "making temporary dir")
545560
defer tmp.RemoveAll()
546561

547-
configFile := tmp.Join("cli-config.yml")
562+
configFile := tmp.Join("arduino-cli.yaml")
548563
err = configFile.WriteFile([]byte(`
549564
board_manager:
550565
additional_urls:

cli/root/root.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package root
1919

2020
import (
21+
"fmt"
2122
"io/ioutil"
2223
"os"
2324

@@ -30,7 +31,6 @@ import (
3031
"github.com/arduino/arduino-cli/cli/upload"
3132
"github.com/arduino/arduino-cli/commands/config"
3233
"github.com/arduino/arduino-cli/commands/generatedocs"
33-
3434
"github.com/arduino/arduino-cli/commands/sketch"
3535
"github.com/arduino/arduino-cli/commands/version"
3636
"github.com/arduino/arduino-cli/common/formatter"
@@ -53,7 +53,7 @@ func Init() *cobra.Command {
5353
}
5454
command.PersistentFlags().BoolVar(&cli.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).")
5555
command.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be [text|json].")
56-
command.PersistentFlags().StringVar(&yamlConfigFile, "config-file", "", "The custom config file (if not specified ./.cli-config.yml will be used).")
56+
command.PersistentFlags().StringVar(&yamlConfigFile, "config-file", "", "The custom config file (if not specified the default will be used).")
5757
command.AddCommand(board.InitCommand())
5858
command.AddCommand(compile.InitCommand())
5959
command.AddCommand(config.InitCommand())
@@ -117,6 +117,7 @@ func preRun(cmd *cobra.Command, args []string) {
117117

118118
// initConfigs initializes the configuration from the specified file.
119119
func initConfigs() {
120+
// Start with default configuration
120121
if conf, err := configs.NewConfiguration(); err != nil {
121122
logrus.WithError(err).Error("Error creating default configuration")
122123
formatter.PrintError(err, "Error creating default configuration")
@@ -125,14 +126,12 @@ func initConfigs() {
125126
cli.Config = conf
126127
}
127128

128-
if yamlConfigFile != "" {
129-
cli.Config.ConfigFile = paths.New(yamlConfigFile)
129+
// Read configuration from global config file
130+
logrus.Info("Checking for config file in: " + cli.Config.ConfigFile.String())
131+
if cli.Config.ConfigFile.Exist() {
132+
readConfigFrom(cli.Config.ConfigFile)
130133
}
131134

132-
logrus.Info("Initiating configuration")
133-
if err := cli.Config.LoadFromYAML(cli.Config.ConfigFile); err != nil {
134-
logrus.WithError(err).Warn("Did not manage to get config file, using default configuration")
135-
}
136135
if cli.Config.IsBundledInDesktopIDE() {
137136
logrus.Info("CLI is bundled into the IDE")
138137
err := cli.Config.LoadFromDesktopIDEPreferences()
@@ -142,6 +141,43 @@ func initConfigs() {
142141
} else {
143142
logrus.Info("CLI is not bundled into the IDE")
144143
}
144+
145+
// Read configuration from parent folders (project config)
146+
if pwd, err := paths.Getwd(); err != nil {
147+
logrus.WithError(err).Warn("Did not manage to find current path")
148+
if path := paths.New("arduino-cli.yaml"); path.Exist() {
149+
readConfigFrom(path)
150+
}
151+
} else {
152+
cli.Config.Navigate(pwd)
153+
}
154+
155+
// Read configuration from old configuration file if found, but output a warning.
156+
if old := paths.New(".cli-config.yml"); old.Exist() {
157+
logrus.Errorf("Old configuration file detected: %s.", old)
158+
logrus.Info("The name of this file has been changed to `arduino-cli.yaml`, please rename the file fix it.")
159+
formatter.PrintError(
160+
fmt.Errorf("WARNING: Old configuration file detected: %s", old),
161+
"The name of this file has been changed to `arduino-cli.yaml`, in a future release we will not support"+
162+
"the old name `.cli-config.yml` anymore. Please rename the file to `arduino-cli.yaml` to silence this warning.")
163+
readConfigFrom(old)
164+
}
165+
166+
// Read configuration from environment vars
145167
cli.Config.LoadFromEnv()
168+
169+
// Read configuration from user specified file
170+
if yamlConfigFile != "" {
171+
cli.Config.ConfigFile = paths.New(yamlConfigFile)
172+
readConfigFrom(cli.Config.ConfigFile)
173+
}
174+
146175
logrus.Info("Configuration set")
147176
}
177+
178+
func readConfigFrom(path *paths.Path) {
179+
logrus.Infof("Reading configuration from %s", path)
180+
if err := cli.Config.LoadFromYAML(path); err != nil {
181+
logrus.WithError(err).Warnf("Could not read configuration from %s", path)
182+
}
183+
}

commands/config/init.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func initInitCommand() *cobra.Command {
4242
initCommand.Flags().BoolVar(&initFlags._default, "default", false,
4343
"If omitted, ask questions to the user about setting configuration properties, otherwise use default configuration.")
4444
initCommand.Flags().StringVar(&initFlags.location, "save-as", "",
45-
"Sets where to save the configuration file [default is ./.cli-config.yml].")
45+
"Sets where to save the configuration file [default is ./arduino-cli.yaml].")
4646
return initCommand
4747
}
4848

@@ -65,8 +65,13 @@ func runInitCommand(cmd *cobra.Command, args []string) {
6565
if filepath == "" {
6666
filepath = cli.Config.ConfigFile.String()
6767
}
68-
err := cli.Config.SaveToYAML(filepath)
69-
if err != nil {
68+
69+
if err := cli.Config.ConfigFile.Parent().MkdirAll(); err != nil {
70+
formatter.PrintError(err, "Cannot create config file.")
71+
os.Exit(cli.ErrGeneric)
72+
}
73+
74+
if err := cli.Config.SaveToYAML(filepath); err != nil {
7075
formatter.PrintError(err, "Cannot create config file.")
7176
os.Exit(cli.ErrGeneric)
7277
}

configs/directories.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,37 @@ package configs
1919

2020
import (
2121
"fmt"
22-
"os"
2322
"os/user"
2423
"runtime"
2524

2625
"github.com/arduino/go-paths-helper"
27-
2826
"github.com/arduino/go-win32-utils"
2927
)
3028

31-
// getDefaultConfigFilePath returns the default path for .cli-config.yml,
32-
// this is the directory where the arduino-cli executable resides.
29+
// getDefaultConfigFilePath returns the default path for arduino-cli.yaml
3330
func getDefaultConfigFilePath() *paths.Path {
34-
executablePath, err := os.Executable()
31+
usr, err := user.Current()
3532
if err != nil {
36-
executablePath = "."
33+
panic(fmt.Errorf("retrieving user home dir: %s", err))
3734
}
38-
return paths.New(executablePath).Parent().Join(".cli-config.yml")
35+
arduinoDataDir := paths.New(usr.HomeDir)
36+
37+
switch runtime.GOOS {
38+
case "linux":
39+
arduinoDataDir = arduinoDataDir.Join(".arduino15")
40+
case "darwin":
41+
arduinoDataDir = arduinoDataDir.Join("Library", "arduino15")
42+
case "windows":
43+
localAppDataPath, err := win32.GetLocalAppDataFolder()
44+
if err != nil {
45+
panic(err)
46+
}
47+
arduinoDataDir = paths.New(localAppDataPath).Join("Arduino15")
48+
default:
49+
panic(fmt.Errorf("unsupported OS: %s", runtime.GOOS))
50+
}
51+
52+
return arduinoDataDir.Join("arduino-cli.yaml")
3953
}
4054

4155
func getDefaultArduinoDataDir() (*paths.Path, error) {

0 commit comments

Comments
 (0)