Skip to content

Commit 7112bc2

Browse files
committed
Change the directory of the configuration files
If you install the arduino cli, the default directory of the configuration file is the location of the executable This is not an ideal configuration for linux or windows With this commit the configuration file is searched in the default configuration folder for each system
1 parent 494bc94 commit 7112bc2

File tree

11 files changed

+377
-11
lines changed

11 files changed

+377
-11
lines changed

Gopkg.lock

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Flags:
295295
-h, --help help for core
296296

297297
Global Flags:
298-
--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")
298+
--config-file string The custom config file (if not specified the default one will be used). (example "/home/megabug/.config/arduino/arduino-cli/.cli-config.yml")
299299
--debug Enables debug output (super verbose, used to debug the CLI).
300300
--format string The output format, can be [text|json]. (default "text")
301301

commands/config/init.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ func runInitCommand(cmd *cobra.Command, args []string) {
6565
if filepath == "" {
6666
filepath = commands.Config.ConfigFile.String()
6767
}
68-
err := commands.Config.SaveToYAML(filepath)
68+
69+
err := os.MkdirAll(commands.Config.ConfigFile.Parent().String(), 0766)
70+
if err != nil {
71+
formatter.PrintError(err, "Cannot create config file.")
72+
os.Exit(commands.ErrGeneric)
73+
}
74+
75+
err = commands.Config.SaveToYAML(filepath)
6976
if err != nil {
7077
formatter.PrintError(err, "Cannot create config file.")
7178
os.Exit(commands.ErrGeneric)

commands/root/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func Init() *cobra.Command {
5656
}
5757
command.PersistentFlags().BoolVar(&commands.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).")
5858
command.PersistentFlags().StringVar(&commands.GlobalFlags.Format, "format", "text", "The output format, can be [text|json].")
59-
command.PersistentFlags().StringVar(&yamlConfigFile, "config-file", "", "The custom config file (if not specified ./.cli-config.yml will be used).")
59+
command.PersistentFlags().StringVar(&yamlConfigFile, "config-file", "", "The custom config file (if not specified the default will be used).")
6060
command.AddCommand(board.InitCommand())
6161
command.AddCommand(compile.InitCommand())
6262
command.AddCommand(config.InitCommand())

configs/directories.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,31 @@ 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"
27+
"github.com/shibukawa/configdir"
2928
)
3029

31-
// getDefaultConfigFilePath returns the default path for .cli-config.yml,
32-
// this is the directory where the arduino-cli executable resides.
30+
// getDefaultConfigFilePath returns the default path for .cli-config.yml. It searches the following directories for an existing .cli-config.yml file:
31+
// - User level configuration folder(e.g. $HOME/.config/<vendor-name>/<application-name>/setting.json in Linux)
32+
// - System level configuration folder(e.g. /etc/xdg/<vendor-name>/<application-name>/setting.json in Linux)
33+
// If it doesn't find one, it defaults to the user level configuration folder
3334
func getDefaultConfigFilePath() *paths.Path {
34-
executablePath, err := os.Executable()
35-
if err != nil {
36-
executablePath = "."
35+
configDirs := configdir.New("arduino", "arduino-cli")
36+
37+
// Search for a suitable configuration file
38+
path := configDirs.QueryFolderContainsFile(".cli-config.yml")
39+
if path != nil {
40+
return paths.New(path.Path, ".cli-config.yml")
3741
}
38-
return paths.New(executablePath).Parent().Join(".cli-config.yml")
42+
// Default to the global configuration
43+
locals := configDirs.QueryFolders(configdir.Global)
44+
return paths.New(locals[0].Path, ".cli-config.yml")
45+
46+
return nil
3947
}
4048

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

vendor/github.com/shibukawa/configdir/LICENSE

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shibukawa/configdir/README.rst

+111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shibukawa/configdir/config.go

+160
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)