Unverified Commit 553b7be3 authored by Massimiliano Pippi's avatar Massimiliano Pippi Committed by GitHub

add option --dest-dir to config init, removed noop --save-as (#575)

parent 28875e6a
......@@ -26,6 +26,10 @@ import (
"github.com/spf13/viper"
)
var destDir string
const defaultFileName = "arduino-cli.yaml"
func initInitCommand() *cobra.Command {
initCommand := &cobra.Command{
Use: "init",
......@@ -37,31 +41,28 @@ func initInitCommand() *cobra.Command {
Args: cobra.NoArgs,
Run: runInitCommand,
}
initCommand.Flags().StringVar(&initFlags.location, "save-as", "",
"Sets where to save the configuration file [default is ./arduino-cli.yaml].")
initCommand.Flags().StringVar(&destDir, "dest-dir", "", "Sets where to save the configuration file.")
return initCommand
}
var initFlags struct {
location string // The custom location of the file to create.
}
func runInitCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino config init`")
if destDir == "" {
destDir = viper.GetString("directories.Data")
}
logrus.Infof("Writing config file to: %s", destDir)
dataDir := viper.GetString("directories.Data")
if err := os.MkdirAll(dataDir, os.FileMode(0755)); err != nil {
feedback.Errorf("Cannot create data directory: %v", err)
if err := os.MkdirAll(destDir, os.FileMode(0755)); err != nil {
feedback.Errorf("Cannot create config file directory: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
configFile := filepath.Join(dataDir, "arduino-cli.yaml")
err := viper.WriteConfigAs(configFile)
if err != nil {
configFile := filepath.Join(destDir, defaultFileName)
if err := viper.WriteConfigAs(configFile); err != nil {
feedback.Errorf("Cannot create config file: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
feedback.Print("Config file written: " + configFile)
logrus.Info("Done")
msg := "Config file written to: " + configFile
logrus.Info(msg)
feedback.Print(msg)
}
# This file is part of arduino-cli.
#
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
#
# This software is released under the GNU General Public License version 3,
# which covers the main part of arduino-cli.
# The terms of this license can be found at:
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# You can be released from the requirements of the above licenses by purchasing
# a commercial license. Buying such a license is mandatory if you want to modify or
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
import os
def test_init(run_command, data_dir, working_dir):
result = run_command("config init")
assert result.ok
assert data_dir in result.stdout
def test_init_dest(run_command, working_dir):
dest = os.path.join(working_dir, "config", "test")
result = run_command("config init --dest-dir " + dest)
assert result.ok
assert dest in result.stdout
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment