Commit a32d52fa authored by Cristian Maglie's avatar Cristian Maglie

Config about 3rd party URLs is no more a singleton

parent 5a02ce4f
......@@ -90,7 +90,7 @@ func InitPackageManager() *packagemanager.PackageManager {
Config.DownloadsDir(),
Config.DataDir.Join("tmp"))
for _, URL := range configs.BoardManagerAdditionalUrls {
for _, URL := range Config.BoardManagerAdditionalUrls {
if err := pm.LoadPackageIndex(URL); err != nil {
formatter.PrintError(err, "Failed to load "+URL.String()+" package index.\n"+
"Try updating all indexes with `"+AppName+" core update-index`.")
......
......@@ -28,7 +28,6 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/configs"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
......@@ -51,7 +50,7 @@ func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
}
func updateIndexes() {
for _, URL := range configs.BoardManagerAdditionalUrls {
for _, URL := range commands.Config.BoardManagerAdditionalUrls {
updateIndex(URL)
}
}
......
/*
* This file is part of arduino-cli.
*
* Copyright 2018 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.
*/
package configs
import "net/url"
var defaultPackageIndexURL, _ = url.Parse("https://downloads.arduino.cc/packages/package_index.json")
// BoardManagerAdditionalUrls contains the additional URL for 3rd party packages
var BoardManagerAdditionalUrls = []*url.URL{defaultPackageIndexURL}
......@@ -20,6 +20,7 @@ package configs
import (
"fmt"
"net/url"
"github.com/arduino/go-paths-helper"
)
......@@ -42,8 +43,13 @@ type Configuration struct {
// the field is true if the CLI is bundled with the Arduino IDE, false if the CLI is running
// standalone or nil if the detection has not been performed.
IDEBundledCheckResult *bool
// BoardManagerAdditionalUrls contains the additional URL for 3rd party packages
BoardManagerAdditionalUrls []*url.URL
}
var defaultPackageIndexURL, _ = url.Parse("https://downloads.arduino.cc/packages/package_index.json")
// NewConfiguration returns a new Configuration with the default values
func NewConfiguration() (*Configuration, error) {
dataDir, err := getDefaultArduinoDataDir()
......@@ -56,9 +62,10 @@ func NewConfiguration() (*Configuration, error) {
}
return &Configuration{
ConfigFile: getDefaultConfigFilePath(),
DataDir: dataDir,
SketchbookDir: sketchbookDir,
ConfigFile: getDefaultConfigFilePath(),
DataDir: dataDir,
SketchbookDir: sketchbookDir,
BoardManagerAdditionalUrls: []*url.URL{defaultPackageIndexURL},
}, nil
}
......
......@@ -87,7 +87,7 @@ func (config *Configuration) LoadFromDesktopIDEPreferences() error {
if URLs, has := props.GetOk("boardsmanager.additional.urls"); has {
for _, URL := range strings.Split(URLs, ",") {
if newURL, err := url.Parse(URL); err == nil {
BoardManagerAdditionalUrls = append(BoardManagerAdditionalUrls, newURL)
config.BoardManagerAdditionalUrls = append(config.BoardManagerAdditionalUrls, newURL)
}
}
}
......
......@@ -81,7 +81,7 @@ func (config *Configuration) LoadFromYAML(path *paths.Path) error {
logrus.WithError(err).Warn("Error parsing config")
continue
}
BoardManagerAdditionalUrls = append(BoardManagerAdditionalUrls, url)
config.BoardManagerAdditionalUrls = append(config.BoardManagerAdditionalUrls, url)
}
}
return nil
......@@ -104,9 +104,9 @@ func (config *Configuration) SerializeToYAML() ([]byte, error) {
Password: ProxyPassword,
}
}
if len(BoardManagerAdditionalUrls) > 1 {
if len(config.BoardManagerAdditionalUrls) > 1 {
c.BoardsManager = &yamlBoardsManagerConfig{AdditionalURLS: []string{}}
for _, URL := range BoardManagerAdditionalUrls[1:] {
for _, URL := range config.BoardManagerAdditionalUrls[1:] {
c.BoardsManager.AdditionalURLS = append(c.BoardsManager.AdditionalURLS, URL.String())
}
}
......
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