From 83d1ce752f0825f30c4c736ccc1951a2d9235f5e Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 15:27:01 +0200 Subject: [PATCH 01/41] add global variables and Info struct in order to inject build time values via ldflags --- global/global.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 global/global.go diff --git a/global/global.go b/global/global.go new file mode 100644 index 00000000000..10c9a5dd152 --- /dev/null +++ b/global/global.go @@ -0,0 +1,57 @@ +package global + +import ( + "os" + "path/filepath" +) + +// appName is the command line name of the Arduino CLI executable on the user system (users may change it) +var appName = filepath.Base(os.Args[0]) + +var ( + application= "arduino-cli" + version = "missing" + commit = "missing" + cvsRef = "missing" + buildDate = "missing" + repository = "missing" +) + + +func GetAppName() string { + return appName +} + +func GetApplication() string { + return application +} + +func GetVersion() string { + return version +} + +func GetCommit() string { + return commit +} + +func GetCvsRef() string { + return cvsRef +} + +func GetBuildDate() string { + return buildDate +} + +func GetRepository() string { + return repository +} + +type Info struct { + Application string `json:"application"` + Version string `json:"version"` + Commit string `json:"commit"` + CvsRef string `json:"cvsRef"` + BuildDate string `json:"buildDate"` + Repository string `json:"repository"` +} + From 86fecf2d2c7c87f1c551dd9b14e3349897107195 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 15:31:41 +0200 Subject: [PATCH 02/41] replace cli.AppName with global variable global.GetAppName() getter --- cli/arduino-cli.yaml | 2 ++ cli/board/attach.go | 7 ++++--- cli/board/board.go | 6 +++--- cli/board/details.go | 3 ++- cli/board/list.go | 3 ++- cli/board/listall.go | 5 +++-- cli/cli.go | 12 ++++-------- cli/compile/compile.go | 3 ++- cli/config/config.go | 4 ++-- cli/config/dump.go | 3 ++- cli/config/init.go | 5 +++-- cli/core/core.go | 4 ++-- cli/core/download.go | 5 +++-- cli/core/install.go | 5 +++-- cli/core/list.go | 3 ++- cli/core/search.go | 3 ++- cli/core/uninstall.go | 3 ++- cli/core/update_index.go | 3 ++- cli/core/upgrade.go | 5 +++-- cli/daemon/daemon.go | 4 ++-- cli/generatedocs/generatedocs.go | 3 ++- cli/lib/download.go | 5 +++-- cli/lib/install.go | 5 +++-- cli/lib/lib.go | 6 +++--- cli/lib/list.go | 3 ++- cli/lib/search.go | 3 ++- cli/lib/uninstall.go | 3 ++- cli/lib/update_index.go | 3 ++- cli/lib/upgrade.go | 3 ++- cli/root/root.go | 5 +++-- cli/sketch/new.go | 3 ++- cli/sketch/sketch.go | 4 ++-- cli/upload/upload.go | 3 ++- cli/version/version.go | 3 ++- commands/compile/compile.go | 2 +- go.mod | 3 +-- go.sum | 2 -- 37 files changed, 84 insertions(+), 63 deletions(-) create mode 100644 cli/arduino-cli.yaml diff --git a/cli/arduino-cli.yaml b/cli/arduino-cli.yaml new file mode 100644 index 00000000000..627a88f471b --- /dev/null +++ b/cli/arduino-cli.yaml @@ -0,0 +1,2 @@ +board_manager: + additional_urls: diff --git a/cli/board/attach.go b/cli/board/attach.go index df59516027e..51e0ddc0c7c 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -19,6 +19,7 @@ package board import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -33,9 +34,9 @@ func initAttachCommand() *cobra.Command { Use: "attach | [sketchPath]", Short: "Attaches a sketch to a board.", Long: "Attaches a sketch to a board.", - Example: " " + cli.AppName + " board attach serial:///dev/tty/ACM0\n" + - " " + cli.AppName + " board attach serial:///dev/tty/ACM0 HelloWorld\n" + - " " + cli.AppName + " board attach arduino:samd:mkr1000", + Example: " " + global.GetAppName() + " board attach serial:///dev/tty/ACM0\n" + + " " + global.GetAppName() + " board attach serial:///dev/tty/ACM0 HelloWorld\n" + + " " + global.GetAppName() + " board attach arduino:samd:mkr1000", Args: cobra.RangeArgs(1, 2), Run: runAttachCommand, } diff --git a/cli/board/board.go b/cli/board/board.go index 21a99b6cf71..42d256ad56b 100644 --- a/cli/board/board.go +++ b/cli/board/board.go @@ -18,7 +18,7 @@ package board import ( - "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -29,9 +29,9 @@ func InitCommand() *cobra.Command { Short: "Arduino board commands.", Long: "Arduino board commands.", Example: " # Lists all connected boards.\n" + - " " + cli.AppName + " board list\n\n" + + " " + global.GetAppName() + " board list\n\n" + " # Attaches a sketch to a board.\n" + - " " + cli.AppName + " board attach serial:///dev/tty/ACM0 mySketch", + " " + global.GetAppName() + " board attach serial:///dev/tty/ACM0 mySketch", } boardCommand.AddCommand(initAttachCommand()) boardCommand.AddCommand(initDetailsCommand()) diff --git a/cli/board/details.go b/cli/board/details.go index 86a9c588f3b..5def87a49a9 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -35,7 +36,7 @@ func initDetailsCommand() *cobra.Command { Use: "details ", Short: "Print details about a board.", Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.", - Example: " " + cli.AppName + " board details arduino:avr:nano", + Example: " " + global.GetAppName() + " board details arduino:avr:nano", Args: cobra.ExactArgs(1), Run: runDetailsCommand, } diff --git a/cli/board/list.go b/cli/board/list.go index 9bf5091b1ad..960ca4c7018 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" "time" @@ -37,7 +38,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "List connected boards.", Long: "Detects and displays a list of connected boards to the current computer.", - Example: " " + cli.AppName + " board list --timeout 10s", + Example: " " + global.GetAppName() + " board list --timeout 10s", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/board/listall.go b/cli/board/listall.go index e7da46c451b..80b9d3170a1 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" @@ -39,8 +40,8 @@ func initListAllCommand() *cobra.Command { "List all boards that have the support platform installed. You can search\n" + "for a specific board if you specify the board name", Example: "" + - " " + cli.AppName + " board listall\n" + - " " + cli.AppName + " board listall zero", + " " + global.GetAppName() + " board listall\n" + + " " + global.GetAppName() + " board listall zero", Args: cobra.ArbitraryArgs, Run: runListAllCommand, } diff --git a/cli/cli.go b/cli/cli.go index 7e2f61a873a..8f492e04ad8 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -20,17 +20,16 @@ package cli import ( "context" "errors" - "os" - "path/filepath" - "github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" - paths "github.com/arduino/go-paths-helper" + "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" + "os" ) // Error codes to be used for os.Exit(). @@ -61,9 +60,6 @@ var GlobalFlags struct { OutputJSON bool // true output in JSON, false output as Text } -// AppName is the command line name of the Arduino CLI executable -var AppName = filepath.Base(os.Args[0]) - var Config *configs.Configuration func packageManagerInitReq() *rpc.InitReq { @@ -116,7 +112,7 @@ func CreateInstance() *rpc.Instance { for _, err := range resp.GetPlatformsIndexErrors() { formatter.PrintError(errors.New(err), "Error loading index") } - formatter.PrintErrorMessage("Launch '" + AppName + " core update-index' to fix or download indexes.") + formatter.PrintErrorMessage("Launch '" + global.GetAppName() + " core update-index' to fix or download indexes.") os.Exit(ErrGeneric) } return resp.GetInstance() diff --git a/cli/compile/compile.go b/cli/compile/compile.go index 0ac8ccaca88..8a9d1ce5f83 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -19,6 +19,7 @@ package compile import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -35,7 +36,7 @@ func InitCommand() *cobra.Command { Use: "compile", Short: "Compiles Arduino sketches.", Long: "Compiles Arduino sketches.", - Example: " " + cli.AppName + " compile -b arduino:avr:uno /home/user/Arduino/MySketch", + Example: " " + global.GetAppName() + " compile -b arduino:avr:uno /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } diff --git a/cli/config/config.go b/cli/config/config.go index 9a7d362da88..5c6bb8dacb3 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -18,7 +18,7 @@ package config import ( - "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -27,7 +27,7 @@ func InitCommand() *cobra.Command { configCommand := &cobra.Command{ Use: "config", Short: "Arduino Configuration Commands.", - Example: " " + cli.AppName + " config init", + Example: " " + global.GetAppName() + " config init", } configCommand.AddCommand(initDumpCommand()) configCommand.AddCommand(initInitCommand()) diff --git a/cli/config/dump.go b/cli/config/dump.go index 3e2843aa237..b12b84ce80d 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -19,6 +19,7 @@ package config import ( "fmt" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -32,7 +33,7 @@ func initDumpCommand() *cobra.Command { Use: "dump", Short: "Prints the current configuration", Long: "Prints the current configuration.", - Example: " " + cli.AppName + " config dump", + Example: " " + global.GetAppName() + " config dump", Args: cobra.NoArgs, Run: runDumpCommand, } diff --git a/cli/config/init.go b/cli/config/init.go index 5c9be35e1a6..d7ee368f608 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -18,6 +18,7 @@ package config import ( + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -33,9 +34,9 @@ func initInitCommand() *cobra.Command { Long: "Initializes a new config file into the default location ($EXE_DIR/cli-config.yml).", Example: "" + " # Creates a config file by asking questions to the user into the default location.\n" + - " " + cli.AppName + " config init\n\n" + + " " + global.GetAppName() + " config init\n\n" + " # Creates a config file with default configuration into default location.\n" + - " " + cli.AppName + " config init --default\n", + " " + global.GetAppName() + " config init --default\n", Args: cobra.NoArgs, Run: runInitCommand, } diff --git a/cli/core/core.go b/cli/core/core.go index 024c4155c34..474b609f5dd 100644 --- a/cli/core/core.go +++ b/cli/core/core.go @@ -18,7 +18,7 @@ package core import ( - "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -28,7 +28,7 @@ func InitCommand() *cobra.Command { Use: "core", Short: "Arduino Core operations.", Long: "Arduino Core operations.", - Example: " " + cli.AppName + " core update-index", + Example: " " + global.GetAppName() + " core update-index", } coreCommand.AddCommand(initDownloadCommand()) coreCommand.AddCommand(initInstallCommand()) diff --git a/cli/core/download.go b/cli/core/download.go index 2d8ad13fe4c..4b2472ee688 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -35,8 +36,8 @@ func initDownloadCommand() *cobra.Command { Short: "Downloads one or more cores and corresponding tool dependencies.", Long: "Downloads one or more cores and corresponding tool dependencies.", Example: "" + - " " + cli.AppName + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" + - " " + cli.AppName + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).", + " " + global.GetAppName() + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" + + " " + global.GetAppName() + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).", Args: cobra.MinimumNArgs(1), Run: runDownloadCommand, } diff --git a/cli/core/install.go b/cli/core/install.go index 4a06cb8dd0b..3b85b3f4096 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -24,6 +24,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -35,9 +36,9 @@ func initInstallCommand() *cobra.Command { Short: "Installs one or more cores and corresponding tool dependencies.", Long: "Installs one or more cores and corresponding tool dependencies.", Example: " # download the latest version of arduino SAMD core.\n" + - " " + cli.AppName + " core install arduino:samd\n\n" + + " " + global.GetAppName() + " core install arduino:samd\n\n" + " # download a specific version (in this case 1.6.9).\n" + - " " + cli.AppName + " core install arduino:samd@1.6.9", + " " + global.GetAppName() + " core install arduino:samd@1.6.9", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } diff --git a/cli/core/list.go b/cli/core/list.go index cd56ef41682..105e98ec693 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -20,6 +20,7 @@ package core import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" @@ -37,7 +38,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "Shows the list of installed platforms.", Long: "Shows the list of installed platforms.", - Example: " " + cli.AppName + " core list", + Example: " " + global.GetAppName() + " core list", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/core/search.go b/cli/core/search.go index 432b75be97b..4939a890edf 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -20,6 +20,7 @@ package core import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" "strings" @@ -38,7 +39,7 @@ func initSearchCommand() *cobra.Command { Use: "search ", Short: "Search for a core in the package index.", Long: "Search for a core in the package index using the specified keywords.", - Example: " " + cli.AppName + " core search MKRZero -v", + Example: " " + global.GetAppName() + " core search MKRZero -v", Args: cobra.MinimumNArgs(1), Run: runSearchCommand, } diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index e593a7559dd..d8930d3a385 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -35,7 +36,7 @@ func initUninstallCommand() *cobra.Command { Use: "uninstall PACKAGER:ARCH ...", Short: "Uninstalls one or more cores and corresponding tool dependencies if no more used.", Long: "Uninstalls one or more cores and corresponding tool dependencies if no more used.", - Example: " " + cli.AppName + " core uninstall arduino:samd\n", + Example: " " + global.GetAppName() + " core uninstall arduino:samd\n", Args: cobra.MinimumNArgs(1), Run: runUninstallCommand, } diff --git a/cli/core/update_index.go b/cli/core/update_index.go index 90dadd596b5..1a527b6dda9 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -34,7 +35,7 @@ func initUpdateIndexCommand() *cobra.Command { Use: "update-index", Short: "Updates the index of cores.", Long: "Updates the index of cores to the latest version.", - Example: " " + cli.AppName + " core update-index", + Example: " " + global.GetAppName() + " core update-index", Args: cobra.NoArgs, Run: runUpdateIndexCommand, } diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 6c061700818..0ee0c48849e 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -36,9 +37,9 @@ func initUpgradeCommand() *cobra.Command { Long: "Upgrades one or all installed platforms to the latest version.", Example: "" + " # upgrade everything to the latest version\n" + - " " + cli.AppName + " core upgrade\n\n" + + " " + global.GetAppName() + " core upgrade\n\n" + " # upgrade arduino:samd to the latest version\n" + - " " + cli.AppName + " core upgrade arduino:samd", + " " + global.GetAppName() + " core upgrade arduino:samd", Run: runUpgradeCommand, } return upgradeCommand diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 5c5dc656e6a..9e69bddf706 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -19,10 +19,10 @@ package daemon import ( "fmt" + "github.com/arduino/arduino-cli/global" "log" "net" - "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/daemon" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" @@ -35,7 +35,7 @@ func InitCommand() *cobra.Command { Use: "daemon", Short: "Run as a daemon", Long: "Running as a daemon the initialization of cores and libraries is done only once.", - Example: " " + cli.AppName + " daemon", + Example: " " + global.GetAppName() + " daemon", Args: cobra.NoArgs, Run: runDaemonCommand, Hidden: true, diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index 01982897af4..bf0bc086849 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -18,6 +18,7 @@ package generatedocs import ( + "github.com/arduino/arduino-cli/global" "os" "path/filepath" @@ -33,7 +34,7 @@ func InitCommand() *cobra.Command { Use: "generate-docs", Short: "Generates bash completion and command manpages.", Long: "Generates bash completion and command manpages.", - Example: " " + cli.AppName + " generate-docs bash-completions", + Example: " " + global.GetAppName() + " generate-docs bash-completions", } command.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "", "Directory where to save generated files. Default is './docs', the directory must exist.") diff --git a/cli/lib/download.go b/cli/lib/download.go index 7598029ce65..7daf2569540 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/common/formatter" @@ -36,8 +37,8 @@ func initDownloadCommand() *cobra.Command { Short: "Downloads one or more libraries without installing them.", Long: "Downloads one or more libraries without installing them.", Example: "" + - " " + cli.AppName + " lib download AudioZero # for the latest version.\n" + - " " + cli.AppName + " lib download AudioZero@1.0.0 # for a specific version.", + " " + global.GetAppName() + " lib download AudioZero # for the latest version.\n" + + " " + global.GetAppName() + " lib download AudioZero@1.0.0 # for a specific version.", Args: cobra.MinimumNArgs(1), Run: runDownloadCommand, } diff --git a/cli/lib/install.go b/cli/lib/install.go index ccac393ee3a..ecdc7a73234 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/commands/lib" @@ -36,8 +37,8 @@ func initInstallCommand() *cobra.Command { Short: "Installs one of more specified libraries into the system.", Long: "Installs one or more specified libraries into the system.", Example: "" + - " " + cli.AppName + " lib install AudioZero # for the latest version.\n" + - " " + cli.AppName + " lib install AudioZero@1.0.0 # for the specific version.", + " " + global.GetAppName() + " lib install AudioZero # for the latest version.\n" + + " " + global.GetAppName() + " lib install AudioZero@1.0.0 # for the specific version.", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } diff --git a/cli/lib/lib.go b/cli/lib/lib.go index 6a6d41096b6..1006d2db2f7 100644 --- a/cli/lib/lib.go +++ b/cli/lib/lib.go @@ -18,7 +18,7 @@ package lib import ( - "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -29,8 +29,8 @@ func InitCommand() *cobra.Command { Short: "Arduino commands about libraries.", Long: "Arduino commands about libraries.", Example: "" + - " " + cli.AppName + " lib install AudioZero\n" + - " " + cli.AppName + " lib update-index", + " " + global.GetAppName() + " lib install AudioZero\n" + + " " + global.GetAppName() + " lib update-index", } libCommand.AddCommand(initDownloadCommand()) libCommand.AddCommand(initInstallCommand()) diff --git a/cli/lib/list.go b/cli/lib/list.go index 4ef1da30679..f15d8b8ade4 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -19,6 +19,7 @@ package lib import ( "fmt" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -36,7 +37,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "Shows a list of all installed libraries.", Long: "Shows a list of all installed libraries.", - Example: " " + cli.AppName + " lib list", + Example: " " + global.GetAppName() + " lib list", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/lib/search.go b/cli/lib/search.go index 9f422917576..dbc551f29b3 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -20,6 +20,7 @@ package lib import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" @@ -39,7 +40,7 @@ func initSearchCommand() *cobra.Command { Use: "search [LIBRARY_NAME]", Short: "Searchs for one or more libraries data.", Long: "Search for one or more libraries data (case insensitive search).", - Example: " " + cli.AppName + " lib search audio", + Example: " " + global.GetAppName() + " lib search audio", Args: cobra.ArbitraryArgs, Run: runSearchCommand, } diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index b790665d56d..5481458f74b 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -35,7 +36,7 @@ func initUninstallCommand() *cobra.Command { Use: "uninstall LIBRARY_NAME(S)", Short: "Uninstalls one or more libraries.", Long: "Uninstalls one or more libraries.", - Example: " " + cli.AppName + " lib uninstall AudioZero", + Example: " " + global.GetAppName() + " lib uninstall AudioZero", Args: cobra.MinimumNArgs(1), Run: runUninstallCommand, } diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 74198f5878f..c5614a49743 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -33,7 +34,7 @@ func initUpdateIndexCommand() *cobra.Command { Use: "update-index", Short: "Updates the libraries index.", Long: "Updates the libraries index to the latest version.", - Example: " " + cli.AppName + " lib update-index", + Example: " " + global.GetAppName() + " lib update-index", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { instance := cli.CreateInstaceIgnorePlatformIndexErrors() diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index 7deecda5acc..7423aea4687 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -18,6 +18,7 @@ package lib import ( + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -35,7 +36,7 @@ func initUpgradeCommand() *cobra.Command { Short: "Upgrades installed libraries.", Long: "This command ungrades all installed libraries to the latest available version." + "To upgrade a single library use the 'install' command.", - Example: " " + cli.AppName + " lib upgrade", + Example: " " + global.GetAppName() + " lib upgrade", Args: cobra.NoArgs, Run: runUpgradeCommand, } diff --git a/cli/root/root.go b/cli/root/root.go index ee6cabcd2bb..78f31f28d70 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -19,6 +19,7 @@ package root import ( "fmt" + "github.com/arduino/arduino-cli/global" "io/ioutil" "os" @@ -48,7 +49,7 @@ func Init() *cobra.Command { Use: "arduino-cli", Short: "Arduino CLI.", Long: "Arduino Command Line Interface (arduino-cli).", - Example: " " + cli.AppName + " [flags...]", + Example: " " + global.GetAppName() + " [flags...]", PersistentPreRun: preRun, } command.PersistentFlags().BoolVar(&cli.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).") @@ -91,7 +92,7 @@ func preRun(cmd *cobra.Command, args []string) { } initConfigs() - logrus.Info(cli.AppName + "-" + cli.Version) + logrus.Info(global.GetAppName() + "-" + cli.Version) logrus.Info("Starting root command preparation (`arduino`)") switch outputFormat { case "text": diff --git a/cli/sketch/new.go b/cli/sketch/new.go index 685aafbfbcf..63555b83482 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -18,6 +18,7 @@ package sketch import ( + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -30,7 +31,7 @@ func initNewCommand() *cobra.Command { Use: "new", Short: "Create a new Sketch", Long: "Create a new Sketch", - Example: " " + cli.AppName + " sketch new MultiBlinker", + Example: " " + global.GetAppName() + " sketch new MultiBlinker", Args: cobra.ExactArgs(1), Run: runNewCommand, } diff --git a/cli/sketch/sketch.go b/cli/sketch/sketch.go index c9035762ec8..f680bdd89aa 100644 --- a/cli/sketch/sketch.go +++ b/cli/sketch/sketch.go @@ -18,7 +18,7 @@ package sketch import ( - "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -28,7 +28,7 @@ func InitCommand() *cobra.Command { Use: "sketch", Short: "Arduino CLI Sketch Commands.", Long: "Arduino CLI Sketch Commands.", - Example: " " + cli.AppName + " sketch new MySketch", + Example: " " + global.GetAppName() + " sketch new MySketch", } sketchCommand.AddCommand(initNewCommand()) //sketchCommand.AddCommand(initSyncCommand()) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index d27bf3a441f..697df38fdfd 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -19,6 +19,7 @@ package upload import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" @@ -35,7 +36,7 @@ func InitCommand() *cobra.Command { Use: "upload", Short: "Upload Arduino sketches.", Long: "Upload Arduino sketches.", - Example: " " + cli.AppName + " upload /home/user/Arduino/MySketch", + Example: " " + global.GetAppName() + " upload /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } diff --git a/cli/version/version.go b/cli/version/version.go index b17afce7880..704a168af0f 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -19,6 +19,7 @@ package version import ( "fmt" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" @@ -30,7 +31,7 @@ func InitCommand() *cobra.Command { Use: "version", Short: "Shows version number of arduino CLI.", Long: "Shows version number of arduino CLI which is installed on your system.", - Example: " " + cli.AppName + " version", + Example: " " + global.GetAppName() + " version", Args: cobra.NoArgs, Run: run, } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index b68e4889fa1..96e1c1b2643 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -76,7 +76,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errS // TODO: Move this error message in `cli` module // errorMessage := fmt.Sprintf( // "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+ - // cli.AppName+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch) + // global.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch) // formatter.PrintErrorMessage(errorMessage) return nil, fmt.Errorf("platform not installed") } diff --git a/go.mod b/go.mod index ad88c2c7426..40f5428b626 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,12 @@ module github.com/arduino/arduino-cli go 1.12 require ( - bou.ke/monkey v1.0.1 // indirect + bou.ke/monkey v1.0.1 github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1 github.com/arduino/go-properties-orderedmap v0.0.0-20181003091528-89278049acd3 github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b - github.com/bouk/monkey v1.0.1 github.com/cmaglie/pb v1.0.27 github.com/codeclysm/cc v1.2.2 // indirect github.com/codeclysm/extract v2.2.0+incompatible diff --git a/go.sum b/go.sum index b0bc99981bf..83c02cc4c9e 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,6 @@ github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwG github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20= github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/bouk/monkey v1.0.1 h1:82kWEtyEjyfkRZb0DaQ5+7O5dJfe3GzF/o97+yUo5d0= -github.com/bouk/monkey v1.0.1/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cmaglie/pb v1.0.27 h1:ynGj8vBXR+dtj4B7Q/W/qGt31771Ux5iFfRQBnwdQiA= github.com/cmaglie/pb v1.0.27/go.mod h1:GilkKZMXYjBA4NxItWFfO+lwkp59PLHQ+IOW/b/kmZI= From 7b2337c7143cf1361a3836ec4e4e65e25208311f Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 15:50:19 +0200 Subject: [PATCH 03/41] replaced cli.Version var with global getter --- cli/root/root.go | 4 ++-- cli/version/version.go | 4 ++-- daemon/daemon.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/root/root.go b/cli/root/root.go index 78f31f28d70..9e470165702 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -19,7 +19,6 @@ package root import ( "fmt" - "github.com/arduino/arduino-cli/global" "io/ioutil" "os" @@ -36,6 +35,7 @@ import ( "github.com/arduino/arduino-cli/cli/version" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" + "github.com/arduino/arduino-cli/global" paths "github.com/arduino/go-paths-helper" "github.com/mattn/go-colorable" "github.com/sirupsen/logrus" @@ -92,7 +92,7 @@ func preRun(cmd *cobra.Command, args []string) { } initConfigs() - logrus.Info(global.GetAppName() + "-" + cli.Version) + logrus.Info(global.GetAppName() + "-" + global.GetVersion()) logrus.Info("Starting root command preparation (`arduino`)") switch outputFormat { case "text": diff --git a/cli/version/version.go b/cli/version/version.go index 704a168af0f..f36d8ba8490 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -19,9 +19,9 @@ package version import ( "fmt" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -46,7 +46,7 @@ type versionOutput struct { func run(cmd *cobra.Command, args []string) { res := &versionOutput{ Command: cmd.Parent().Name(), - Version: cli.Version, + Version: global.GetVersion(), } if cli.OutputJSONOrElse(res) { fmt.Printf("%s version %s\n", res.Command, res.Version) diff --git a/daemon/daemon.go b/daemon/daemon.go index 52a7bfdfa9a..3c0589c8fdf 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -26,13 +26,13 @@ import ( "log" "net" - "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/commands/compile" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/commands/upload" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" "google.golang.org/grpc" @@ -121,7 +121,7 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In } func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq) (*rpc.VersionResp, error) { - return &rpc.VersionResp{Version: cli.Version}, nil + return &rpc.VersionResp{Version: global.GetVersion()}, nil } func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error { From 232632fcd6c7a41b779372b563eb0313642e3ae7 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 18:41:10 +0200 Subject: [PATCH 04/41] add .idea to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0dd0591bbc0..0ff7b75a308 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /cmd/formatter/debug.test /arduino-cli.yaml /wiki +.idea \ No newline at end of file From 1008f1f572cbd8104f0477ec537797c4af6c2355 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 18:41:35 +0200 Subject: [PATCH 05/41] re organize imports --- cli/arduino-cli.yaml | 2 -- cli/board/attach.go | 2 +- cli/board/details.go | 2 +- cli/board/list.go | 2 +- cli/board/listall.go | 2 +- cli/cli.go | 3 ++- cli/compile/compile.go | 2 +- cli/output.go | 3 +-- global/global.go | 14 ++++++-------- 9 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 cli/arduino-cli.yaml diff --git a/cli/arduino-cli.yaml b/cli/arduino-cli.yaml deleted file mode 100644 index 627a88f471b..00000000000 --- a/cli/arduino-cli.yaml +++ /dev/null @@ -1,2 +0,0 @@ -board_manager: - additional_urls: diff --git a/cli/board/attach.go b/cli/board/attach.go index 51e0ddc0c7c..aed25a8fcc0 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -19,12 +19,12 @@ package board import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" ) diff --git a/cli/board/details.go b/cli/board/details.go index 5def87a49a9..2c9d002ea70 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -20,12 +20,12 @@ package board import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" diff --git a/cli/board/list.go b/cli/board/list.go index 960ca4c7018..4cb54a9150f 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "time" @@ -28,6 +27,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" diff --git a/cli/board/listall.go b/cli/board/listall.go index 80b9d3170a1..008057ecadf 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -20,13 +20,13 @@ package board import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" diff --git a/cli/cli.go b/cli/cli.go index 8f492e04ad8..328344030b6 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -20,6 +20,8 @@ package cli import ( "context" "errors" + "os" + "github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" "github.com/arduino/arduino-cli/commands" @@ -29,7 +31,6 @@ import ( "github.com/arduino/arduino-cli/rpc" "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" - "os" ) // Error codes to be used for os.Exit(). diff --git a/cli/compile/compile.go b/cli/compile/compile.go index 8a9d1ce5f83..db98631b59f 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -19,12 +19,12 @@ package compile import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/compile" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" diff --git a/cli/output.go b/cli/output.go index fdd0f78be27..bcbcf940142 100644 --- a/cli/output.go +++ b/cli/output.go @@ -22,10 +22,9 @@ import ( "fmt" "os" - "github.com/arduino/arduino-cli/output" - "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" ) diff --git a/global/global.go b/global/global.go index 10c9a5dd152..c62b759b8e2 100644 --- a/global/global.go +++ b/global/global.go @@ -9,15 +9,14 @@ import ( var appName = filepath.Base(os.Args[0]) var ( - application= "arduino-cli" - version = "missing" - commit = "missing" - cvsRef = "missing" - buildDate = "missing" - repository = "missing" + application = "arduino-cli" + version = "missing" + commit = "missing" + cvsRef = "missing" + buildDate = "missing" + repository = "missing" ) - func GetAppName() string { return appName } @@ -54,4 +53,3 @@ type Info struct { BuildDate string `json:"buildDate"` Repository string `json:"repository"` } - From 4c44d5d7a68a4484cad875100951e463ef51ba04 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 18:43:44 +0200 Subject: [PATCH 06/41] add license to global.go --- global/global.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/global/global.go b/global/global.go index c62b759b8e2..bd16d80f9fb 100644 --- a/global/global.go +++ b/global/global.go @@ -1,3 +1,20 @@ +/* + * 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 global import ( From 04d91bef2727232a20649b996a961b7eab6e27f9 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 18:45:50 +0200 Subject: [PATCH 07/41] add hardcoded fallback version string --- global/global.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global/global.go b/global/global.go index bd16d80f9fb..9a964b2c76e 100644 --- a/global/global.go +++ b/global/global.go @@ -27,7 +27,7 @@ var appName = filepath.Base(os.Args[0]) var ( application = "arduino-cli" - version = "missing" + version = "0.3.6-alpha.preview" commit = "missing" cvsRef = "missing" buildDate = "missing" From 6018efdd8e08282e90d302e4661b5e489144afeb Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 19:08:57 +0200 Subject: [PATCH 08/41] organize imports step2 --- cli/config/dump.go | 2 +- cli/config/init.go | 2 +- cli/core/download.go | 2 +- cli/core/list.go | 2 +- cli/daemon/daemon.go | 2 +- cli/generatedocs/generatedocs.go | 2 +- cli/lib/download.go | 5 ++--- cli/lib/install.go | 7 +++---- cli/lib/list.go | 2 +- cli/lib/search.go | 3 +-- cli/lib/uninstall.go | 2 +- cli/lib/update_index.go | 2 +- cli/lib/upgrade.go | 2 +- cli/sketch/new.go | 2 +- cli/upload/upload.go | 2 +- 15 files changed, 18 insertions(+), 21 deletions(-) diff --git a/cli/config/dump.go b/cli/config/dump.go index b12b84ce80d..f277b7f4f00 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -19,11 +19,11 @@ package config import ( "fmt" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/config/init.go b/cli/config/init.go index d7ee368f608..579ed48a8f9 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -18,11 +18,11 @@ package config import ( - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/download.go b/cli/core/download.go index 4b2472ee688..6a8fc66b061 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -19,12 +19,12 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/core/list.go b/cli/core/list.go index 105e98ec693..67492498153 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -20,13 +20,13 @@ package core import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 9e69bddf706..2d757cb342a 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -19,11 +19,11 @@ package daemon import ( "fmt" - "github.com/arduino/arduino-cli/global" "log" "net" "github.com/arduino/arduino-cli/daemon" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" "google.golang.org/grpc" diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index bf0bc086849..83eee15e42d 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -18,11 +18,11 @@ package generatedocs import ( - "github.com/arduino/arduino-cli/global" "os" "path/filepath" "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" diff --git a/cli/lib/download.go b/cli/lib/download.go index 7daf2569540..07af7e6191e 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -19,14 +19,13 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" + "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" ) diff --git a/cli/lib/install.go b/cli/lib/install.go index ecdc7a73234..0f4afcd9954 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -19,15 +19,14 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" - "github.com/arduino/arduino-cli/commands/lib" - "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" ) diff --git a/cli/lib/list.go b/cli/lib/list.go index f15d8b8ade4..08b730632da 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -19,12 +19,12 @@ package lib import ( "fmt" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/gosuri/uitable" "github.com/sirupsen/logrus" diff --git a/cli/lib/search.go b/cli/lib/search.go index dbc551f29b3..4c731b7c5a6 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -20,15 +20,14 @@ package lib import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" - "strings" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index 5481458f74b..1fb7f5f5c8b 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -19,13 +19,13 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index c5614a49743..032a96d2c26 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -19,12 +19,12 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/spf13/cobra" ) diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index 7423aea4687..cd230102928 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -18,12 +18,12 @@ package lib import ( - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/sketch/new.go b/cli/sketch/new.go index 63555b83482..5469d23b028 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -18,11 +18,11 @@ package sketch import ( - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 697df38fdfd..e7d4527c1ec 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -19,12 +19,12 @@ package upload import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" From ca62d75c0e17d3ff1563901576acc03505a58d94 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 21:27:51 +0200 Subject: [PATCH 09/41] organize imports step3 --- cli/core/search.go | 2 +- cli/core/uninstall.go | 2 +- cli/core/update_index.go | 2 +- cli/core/upgrade.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/core/search.go b/cli/core/search.go index 4939a890edf..01b1d77ea7d 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -20,7 +20,6 @@ package core import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "strings" @@ -28,6 +27,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index d8930d3a385..9ef897caf99 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -19,12 +19,12 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" diff --git a/cli/core/update_index.go b/cli/core/update_index.go index 1a527b6dda9..cee08e9c64e 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -19,12 +19,12 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 0ee0c48849e..a8ff7a15caa 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -19,12 +19,12 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" "github.com/spf13/cobra" From 9456352daf9665e5e9a8d85358209c272346d6dc Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 15:31:41 +0200 Subject: [PATCH 10/41] replace cli.AppName with global variable global.GetAppName() getter --- cli/arduino-cli.yaml | 2 ++ cli/board/attach.go | 1 + cli/board/details.go | 1 + cli/board/list.go | 1 + cli/board/listall.go | 1 + cli/compile/compile.go | 1 + cli/config/dump.go | 1 + cli/config/init.go | 1 + cli/core/download.go | 1 + cli/core/list.go | 1 + cli/core/search.go | 1 + cli/core/uninstall.go | 1 + cli/core/update_index.go | 1 + cli/core/upgrade.go | 1 + cli/daemon/daemon.go | 1 + cli/generatedocs/generatedocs.go | 1 + cli/lib/download.go | 1 + cli/lib/install.go | 1 + cli/lib/list.go | 1 + cli/lib/search.go | 1 + cli/lib/uninstall.go | 1 + cli/lib/update_index.go | 1 + cli/lib/upgrade.go | 1 + cli/sketch/new.go | 1 + cli/upload/upload.go | 1 + cli/version/version.go | 1 + 26 files changed, 27 insertions(+) create mode 100644 cli/arduino-cli.yaml diff --git a/cli/arduino-cli.yaml b/cli/arduino-cli.yaml new file mode 100644 index 00000000000..627a88f471b --- /dev/null +++ b/cli/arduino-cli.yaml @@ -0,0 +1,2 @@ +board_manager: + additional_urls: diff --git a/cli/board/attach.go b/cli/board/attach.go index aed25a8fcc0..20b8352e188 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -19,6 +19,7 @@ package board import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/board/details.go b/cli/board/details.go index 2c9d002ea70..3ea6e6506c6 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/board/list.go b/cli/board/list.go index 4cb54a9150f..d286eec667d 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" "time" diff --git a/cli/board/listall.go b/cli/board/listall.go index 008057ecadf..4fa50b79c5d 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" diff --git a/cli/compile/compile.go b/cli/compile/compile.go index db98631b59f..87acbcbf2c4 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -19,6 +19,7 @@ package compile import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/config/dump.go b/cli/config/dump.go index f277b7f4f00..34575d02abb 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -19,6 +19,7 @@ package config import ( "fmt" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/config/init.go b/cli/config/init.go index 579ed48a8f9..5830b562b99 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -18,6 +18,7 @@ package config import ( + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/download.go b/cli/core/download.go index 6a8fc66b061..06dfc827fe8 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/list.go b/cli/core/list.go index 67492498153..938a525f3e9 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -20,6 +20,7 @@ package core import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" diff --git a/cli/core/search.go b/cli/core/search.go index 01b1d77ea7d..f482747630e 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -20,6 +20,7 @@ package core import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" "strings" diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 9ef897caf99..708e1bf550b 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/update_index.go b/cli/core/update_index.go index cee08e9c64e..00e1ccc7408 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index a8ff7a15caa..772a1937121 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -19,6 +19,7 @@ package core import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 2d757cb342a..9aeb6771ddd 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -19,6 +19,7 @@ package daemon import ( "fmt" + "github.com/arduino/arduino-cli/global" "log" "net" diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index 83eee15e42d..b091662b5b1 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -18,6 +18,7 @@ package generatedocs import ( + "github.com/arduino/arduino-cli/global" "os" "path/filepath" diff --git a/cli/lib/download.go b/cli/lib/download.go index 07af7e6191e..33597a73927 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" diff --git a/cli/lib/install.go b/cli/lib/install.go index 0f4afcd9954..2ee4a5b928f 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" diff --git a/cli/lib/list.go b/cli/lib/list.go index 08b730632da..01ae9528824 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -19,6 +19,7 @@ package lib import ( "fmt" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/lib/search.go b/cli/lib/search.go index 4c731b7c5a6..ecf5c18f6e8 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -20,6 +20,7 @@ package lib import ( "context" "fmt" + "github.com/arduino/arduino-cli/global" "os" "sort" "strings" diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index 1fb7f5f5c8b..6f52ca6c3df 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 032a96d2c26..34a3f72a069 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -19,6 +19,7 @@ package lib import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index cd230102928..fdd55f03ffc 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -18,6 +18,7 @@ package lib import ( + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/sketch/new.go b/cli/sketch/new.go index 5469d23b028..3d1eea24cd4 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -18,6 +18,7 @@ package sketch import ( + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/upload/upload.go b/cli/upload/upload.go index e7d4527c1ec..11a0c15d7e5 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -19,6 +19,7 @@ package upload import ( "context" + "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/version/version.go b/cli/version/version.go index f36d8ba8490..099e29f650f 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -19,6 +19,7 @@ package version import ( "fmt" + "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/global" From 0fba5284bf2157e78de5beb38a1735b5d93e77ec Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Wed, 5 Jun 2019 18:41:35 +0200 Subject: [PATCH 11/41] re organize imports --- cli/arduino-cli.yaml | 2 -- cli/board/attach.go | 1 - cli/board/details.go | 1 - cli/board/list.go | 1 - cli/board/listall.go | 1 - cli/compile/compile.go | 1 - cli/config/dump.go | 1 - cli/config/init.go | 1 - cli/core/download.go | 1 - cli/core/list.go | 1 - cli/core/search.go | 1 - cli/core/uninstall.go | 1 - cli/core/update_index.go | 1 - cli/core/upgrade.go | 1 - cli/daemon/daemon.go | 1 - cli/generatedocs/generatedocs.go | 1 - cli/lib/download.go | 1 - cli/lib/install.go | 1 - cli/lib/list.go | 1 - cli/lib/search.go | 1 - cli/lib/uninstall.go | 1 - cli/lib/update_index.go | 1 - cli/lib/upgrade.go | 1 - cli/sketch/new.go | 1 - cli/upload/upload.go | 1 - 25 files changed, 26 deletions(-) delete mode 100644 cli/arduino-cli.yaml diff --git a/cli/arduino-cli.yaml b/cli/arduino-cli.yaml deleted file mode 100644 index 627a88f471b..00000000000 --- a/cli/arduino-cli.yaml +++ /dev/null @@ -1,2 +0,0 @@ -board_manager: - additional_urls: diff --git a/cli/board/attach.go b/cli/board/attach.go index 20b8352e188..aed25a8fcc0 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -19,7 +19,6 @@ package board import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/board/details.go b/cli/board/details.go index 3ea6e6506c6..2c9d002ea70 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/board/list.go b/cli/board/list.go index d286eec667d..4cb54a9150f 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "time" diff --git a/cli/board/listall.go b/cli/board/listall.go index 4fa50b79c5d..008057ecadf 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" diff --git a/cli/compile/compile.go b/cli/compile/compile.go index 87acbcbf2c4..db98631b59f 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -19,7 +19,6 @@ package compile import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/config/dump.go b/cli/config/dump.go index 34575d02abb..f277b7f4f00 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -19,7 +19,6 @@ package config import ( "fmt" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/config/init.go b/cli/config/init.go index 5830b562b99..579ed48a8f9 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -18,7 +18,6 @@ package config import ( - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/download.go b/cli/core/download.go index 06dfc827fe8..6a8fc66b061 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -19,7 +19,6 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/list.go b/cli/core/list.go index 938a525f3e9..67492498153 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -20,7 +20,6 @@ package core import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" diff --git a/cli/core/search.go b/cli/core/search.go index f482747630e..01b1d77ea7d 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -20,7 +20,6 @@ package core import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "strings" diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 708e1bf550b..9ef897caf99 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -19,7 +19,6 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/update_index.go b/cli/core/update_index.go index 00e1ccc7408..cee08e9c64e 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -19,7 +19,6 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 772a1937121..a8ff7a15caa 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -19,7 +19,6 @@ package core import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 9aeb6771ddd..2d757cb342a 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -19,7 +19,6 @@ package daemon import ( "fmt" - "github.com/arduino/arduino-cli/global" "log" "net" diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index b091662b5b1..83eee15e42d 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -18,7 +18,6 @@ package generatedocs import ( - "github.com/arduino/arduino-cli/global" "os" "path/filepath" diff --git a/cli/lib/download.go b/cli/lib/download.go index 33597a73927..07af7e6191e 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -19,7 +19,6 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" diff --git a/cli/lib/install.go b/cli/lib/install.go index 2ee4a5b928f..0f4afcd9954 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -19,7 +19,6 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" diff --git a/cli/lib/list.go b/cli/lib/list.go index 01ae9528824..08b730632da 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -19,7 +19,6 @@ package lib import ( "fmt" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/lib/search.go b/cli/lib/search.go index ecf5c18f6e8..4c731b7c5a6 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -20,7 +20,6 @@ package lib import ( "context" "fmt" - "github.com/arduino/arduino-cli/global" "os" "sort" "strings" diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index 6f52ca6c3df..1fb7f5f5c8b 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -19,7 +19,6 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 34a3f72a069..032a96d2c26 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -19,7 +19,6 @@ package lib import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index fdd55f03ffc..cd230102928 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -18,7 +18,6 @@ package lib import ( - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/sketch/new.go b/cli/sketch/new.go index 3d1eea24cd4..5469d23b028 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -18,7 +18,6 @@ package sketch import ( - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 11a0c15d7e5..e7d4527c1ec 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -19,7 +19,6 @@ package upload import ( "context" - "github.com/arduino/arduino-cli/global" "os" "github.com/arduino/arduino-cli/cli" From 241292efa7a2f7a098574b2dc8d2b6c3d7056f67 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 31 May 2019 18:34:29 +0200 Subject: [PATCH 12/41] add User-Agent header to downloader helper configuration --- arduino/resources/helpers.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arduino/resources/helpers.go b/arduino/resources/helpers.go index 8894a630067..6e82e2d2967 100644 --- a/arduino/resources/helpers.go +++ b/arduino/resources/helpers.go @@ -19,9 +19,12 @@ package resources import ( "fmt" + "net/http" "os" + "runtime" - paths "github.com/arduino/go-paths-helper" + "github.com/arduino/arduino-cli/global" + "github.com/arduino/go-paths-helper" "go.bug.st/downloader" ) @@ -73,5 +76,18 @@ func (r *DownloadResource) Download(downloadDir *paths.Path) (*downloader.Downlo return nil, fmt.Errorf("getting archive file info: %s", err) } - return downloader.Download(path.String(), r.URL) + downloadConfig := r.ConfigureDownloader() + return downloader.DownloadWithConfig(path.String(), r.URL, downloadConfig) +} + +// ConfigureDownloader adds additional config to the downloader helper +func (r *DownloadResource) ConfigureDownloader() downloader.Config { + userAgentHeaderValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", global.GetApplication(), + global.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), global.GetCommit(), global.GetBuildDate()) + downloadConfig := downloader.Config{ + RequestHeaders: http.Header{ + "User-Agent": []string{userAgentHeaderValue}, + }, + } + return downloadConfig } From a2f411739ad09334f58ca58f82c9c0b8e390f94f Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 4 Jun 2019 18:48:56 +0200 Subject: [PATCH 13/41] add testing for user agent-string generation --- arduino/resources/helpers_test.go | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 arduino/resources/helpers_test.go diff --git a/arduino/resources/helpers_test.go b/arduino/resources/helpers_test.go new file mode 100644 index 00000000000..d8c9ec31a4c --- /dev/null +++ b/arduino/resources/helpers_test.go @@ -0,0 +1,84 @@ +/* + * 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 resources + +import ( + "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "runtime" + "strings" + "testing" + + "github.com/arduino/arduino-cli/global" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +type EchoHandler struct{} + +// EchoHandler echos back the request as a response if used as http handler +func (h *EchoHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { + request.Write(writer) +} + +func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { + goldUserAgentString := "User-Agent: " + fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", global.GetApplication(), + global.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), global.GetCommit(), global.GetBuildDate()) + + tmp, err := paths.MkTempDir("", "") + require.NoError(t, err) + defer tmp.RemoveAll() + + // startup echo server + srv := httptest.NewServer(&EchoHandler{}) + defer srv.Close() + + r := &DownloadResource{ + ArchiveFileName: "echo.txt", + CachePath: "cache", + URL: srv.URL, + } + + d, err := r.Download(tmp) + require.NoError(t, err) + err = d.Run() + require.NoError(t, err) + + // leverage the download helper to download the echo for the request made by the downloader itself + // + // expect something like: + // GET /echo HTTP/1.1 + // Host: 127.0.0.1:64999 + // User-Agent: arduino-cli/0.3.6-alpha.preview (amd64; linux; go1.10) Commit:missing/Build:missing + // Accept-Encoding: gzip + + b, err := ioutil.ReadFile(tmp.String() + "/cache/echo.txt") // just pass the file name + require.NoError(t, err) + + requestLines := strings.Split(string(b), "\r\n") + userAgentHeaderString := "" + for _, line := range requestLines { + if strings.Contains(line, "User-Agent: ") { + userAgentHeaderString = line + } + } + require.Equal(t, goldUserAgentString, userAgentHeaderString) + +} From de1e994daeb9e15256eaea190d6a8360f2716fba Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 09:52:06 +0200 Subject: [PATCH 14/41] refactor global package into version package and rename and replace having cli login,logout,validate removed --- arduino/resources/helpers.go | 2 +- arduino/resources/helpers_test.go | 2 +- cli/board/attach.go | 2 +- cli/board/board.go | 2 +- cli/board/details.go | 2 +- cli/board/list.go | 2 +- cli/board/listall.go | 2 +- cli/cli.go | 2 +- cli/compile/compile.go | 2 +- cli/config/config.go | 2 +- cli/config/dump.go | 2 +- cli/config/init.go | 2 +- cli/core/core.go | 2 +- cli/core/download.go | 2 +- cli/core/install.go | 2 +- cli/core/list.go | 2 +- cli/core/search.go | 2 +- cli/core/uninstall.go | 2 +- cli/core/update_index.go | 2 +- cli/core/upgrade.go | 2 +- cli/daemon/daemon.go | 2 +- cli/generatedocs/generatedocs.go | 2 +- cli/lib/download.go | 2 +- cli/lib/install.go | 2 +- cli/lib/lib.go | 2 +- cli/lib/list.go | 2 +- cli/lib/search.go | 2 +- cli/lib/uninstall.go | 2 +- cli/lib/update_index.go | 2 +- cli/lib/upgrade.go | 2 +- cli/root/root.go | 4 ++-- cli/sketch/new.go | 2 +- cli/sketch/sketch.go | 2 +- cli/upload/upload.go | 2 +- cli/version/version.go | 2 +- commands/compile/compile.go | 2 +- daemon/daemon.go | 2 +- global/global.go => version/version.go | 0 38 files changed, 38 insertions(+), 38 deletions(-) rename global/global.go => version/version.go (100%) diff --git a/arduino/resources/helpers.go b/arduino/resources/helpers.go index 6e82e2d2967..5b1ce430226 100644 --- a/arduino/resources/helpers.go +++ b/arduino/resources/helpers.go @@ -23,7 +23,7 @@ import ( "os" "runtime" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "go.bug.st/downloader" ) diff --git a/arduino/resources/helpers_test.go b/arduino/resources/helpers_test.go index d8c9ec31a4c..6bcc1aa3c89 100644 --- a/arduino/resources/helpers_test.go +++ b/arduino/resources/helpers_test.go @@ -26,7 +26,7 @@ import ( "strings" "testing" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" ) diff --git a/cli/board/attach.go b/cli/board/attach.go index aed25a8fcc0..79c25144c25 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/board/board.go b/cli/board/board.go index 42d256ad56b..a18de044573 100644 --- a/cli/board/board.go +++ b/cli/board/board.go @@ -18,7 +18,7 @@ package board import ( - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/board/details.go b/cli/board/details.go index 2c9d002ea70..12cf549a922 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -25,9 +25,9 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/board/list.go b/cli/board/list.go index 4cb54a9150f..e30faf6f8b6 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -27,9 +27,9 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/board/listall.go b/cli/board/listall.go index 008057ecadf..91fc8ca78e5 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -26,9 +26,9 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/cli.go b/cli/cli.go index 328344030b6..2aeb78d9c63 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -27,8 +27,8 @@ import ( "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" ) diff --git a/cli/compile/compile.go b/cli/compile/compile.go index db98631b59f..0789bb56d10 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/compile" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" ) diff --git a/cli/config/config.go b/cli/config/config.go index 5c6bb8dacb3..0c14bd9455c 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -18,7 +18,7 @@ package config import ( - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/config/dump.go b/cli/config/dump.go index f277b7f4f00..756e9f8dbd2 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -23,7 +23,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/config/init.go b/cli/config/init.go index 579ed48a8f9..b9f925cf947 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -22,7 +22,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/core.go b/cli/core/core.go index 474b609f5dd..528d44794f3 100644 --- a/cli/core/core.go +++ b/cli/core/core.go @@ -18,7 +18,7 @@ package core import ( - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/core/download.go b/cli/core/download.go index 6a8fc66b061..a0002bd36c3 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/install.go b/cli/core/install.go index 3b85b3f4096..8fc9d6410c7 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/list.go b/cli/core/list.go index 67492498153..749fab45a96 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -26,9 +26,9 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/search.go b/cli/core/search.go index 01b1d77ea7d..5ea4f3f9882 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -27,9 +27,9 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 9ef897caf99..8d6867346b3 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -24,9 +24,9 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/update_index.go b/cli/core/update_index.go index cee08e9c64e..379d95bc788 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index a8ff7a15caa..4bf0f132f00 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 2d757cb342a..07744bf6ab3 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -23,8 +23,8 @@ import ( "net" "github.com/arduino/arduino-cli/daemon" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" "google.golang.org/grpc" ) diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index 83eee15e42d..41950782894 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -22,7 +22,7 @@ import ( "path/filepath" "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" diff --git a/cli/lib/download.go b/cli/lib/download.go index 07af7e6191e..5459ba69115 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -25,8 +25,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/lib/install.go b/cli/lib/install.go index 0f4afcd9954..585a710286e 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -25,8 +25,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/lib/lib.go b/cli/lib/lib.go index 1006d2db2f7..7610aa6718e 100644 --- a/cli/lib/lib.go +++ b/cli/lib/lib.go @@ -18,7 +18,7 @@ package lib import ( - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/lib/list.go b/cli/lib/list.go index 08b730632da..53faeb93e4b 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/gosuri/uitable" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/lib/search.go b/cli/lib/search.go index 4c731b7c5a6..bd9e11ce692 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -27,8 +27,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" semver "go.bug.st/relaxed-semver" diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index 1fb7f5f5c8b..ed6ce1728bf 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -25,8 +25,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 032a96d2c26..27c6516671a 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index cd230102928..c2e0dd6e030 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -23,8 +23,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/net/context" diff --git a/cli/root/root.go b/cli/root/root.go index 9e470165702..63047104030 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -35,7 +35,7 @@ import ( "github.com/arduino/arduino-cli/cli/version" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" paths "github.com/arduino/go-paths-helper" "github.com/mattn/go-colorable" "github.com/sirupsen/logrus" @@ -127,7 +127,7 @@ func initConfigs() { cli.Config = conf } - // Read configuration from global config file + // Read configuration from version config file logrus.Info("Checking for config file in: " + cli.Config.ConfigFile.String()) if cli.Config.ConfigFile.Exist() { readConfigFrom(cli.Config.ConfigFile) diff --git a/cli/sketch/new.go b/cli/sketch/new.go index 5469d23b028..a590b26b8c7 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -22,7 +22,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/sketch/sketch.go b/cli/sketch/sketch.go index f680bdd89aa..3ef1b749689 100644 --- a/cli/sketch/sketch.go +++ b/cli/sketch/sketch.go @@ -18,7 +18,7 @@ package sketch import ( - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index e7d4527c1ec..5b3cd6483c5 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -24,8 +24,8 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" ) diff --git a/cli/version/version.go b/cli/version/version.go index 099e29f650f..d7bd2403f72 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -22,7 +22,7 @@ import ( "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/global" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 96e1c1b2643..08a0dfb2cb9 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -76,7 +76,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errS // TODO: Move this error message in `cli` module // errorMessage := fmt.Sprintf( // "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+ - // global.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch) + // version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch) // formatter.PrintErrorMessage(errorMessage) return nil, fmt.Errorf("platform not installed") } diff --git a/daemon/daemon.go b/daemon/daemon.go index 3c0589c8fdf..012931547e4 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -32,8 +32,8 @@ import ( "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/commands/upload" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" "google.golang.org/grpc" ) diff --git a/global/global.go b/version/version.go similarity index 100% rename from global/global.go rename to version/version.go From c1196a5d75e949fe149e0cb523b6e085243870e2 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 10:45:52 +0200 Subject: [PATCH 15/41] refactor versioning variables in version package and implement Info struct wihth String method --- version/version.go | 53 ++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/version/version.go b/version/version.go index 9a964b2c76e..047e3cf6155 100644 --- a/version/version.go +++ b/version/version.go @@ -3,7 +3,7 @@ * * Copyright 2018 ARDUINO SA (http://www.arduino.cc/) * - * This software is released under the GNU General Public License version 3, + * This software is released under the GNU General Public License defaultVersionString 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 @@ -18,20 +18,21 @@ package global import ( + "fmt" "os" "path/filepath" + "time" ) // appName is the command line name of the Arduino CLI executable on the user system (users may change it) var appName = filepath.Base(os.Args[0]) var ( - application = "arduino-cli" - version = "0.3.6-alpha.preview" - commit = "missing" - cvsRef = "missing" - buildDate = "missing" - repository = "missing" + application = "arduino-cli" + defaultVersionString = "0.3.6-alpha.preview" + versionString = "" + commit = "missing" + buildDate = time.Time{} ) func GetAppName() string { @@ -43,30 +44,40 @@ func GetApplication() string { } func GetVersion() string { - return version + return defaultVersionString } func GetCommit() string { return commit } -func GetCvsRef() string { - return cvsRef +func GetBuildDate() string { + return "" } -func GetBuildDate() string { - return buildDate +type Info struct { + Application string `json:"Application"` + VersionString string `json:"VersionString"` + Commit string `json:"Commit"` + BuildDate time.Time `json:"BuildDate"` } -func GetRepository() string { - return repository +func NewInfo(application string, versionString string, commit string) *Info { + return &Info{ + Application: application, + VersionString: versionString, + Commit: commit, + BuildDate: buildDate, + } } -type Info struct { - Application string `json:"application"` - Version string `json:"version"` - Commit string `json:"commit"` - CvsRef string `json:"cvsRef"` - BuildDate string `json:"buildDate"` - Repository string `json:"repository"` +func (i *Info) String() string { + return fmt.Sprintf("%s Version: %s Commit: %s BuildDate: %s", i.Application, i.VersionString, i.Commit, i.BuildDate) +} + +func init() { + if versionString == "" { + versionString = defaultVersionString + } + buildDate = time.Now().UTC() } From 8a832d587bb8e016dcf25d62d7bfb4800ce9ce9d Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 12:52:03 +0200 Subject: [PATCH 16/41] refactor Info cosntructor to use directly package vars and renamed package from global to version --- version/version.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/version/version.go b/version/version.go index 047e3cf6155..28cf174a849 100644 --- a/version/version.go +++ b/version/version.go @@ -15,32 +15,26 @@ * a commercial license, send an email to license@arduino.cc. */ -package global +package version import ( "fmt" - "os" - "path/filepath" "time" ) -// appName is the command line name of the Arduino CLI executable on the user system (users may change it) -var appName = filepath.Base(os.Args[0]) - var ( - application = "arduino-cli" defaultVersionString = "0.3.6-alpha.preview" versionString = "" - commit = "missing" + commit = "" buildDate = time.Time{} ) func GetAppName() string { - return appName + return "" } func GetApplication() string { - return application + return "" } func GetVersion() string { @@ -62,7 +56,7 @@ type Info struct { BuildDate time.Time `json:"BuildDate"` } -func NewInfo(application string, versionString string, commit string) *Info { +func NewInfo(application string) *Info { return &Info{ Application: application, VersionString: versionString, From 7411926670fab48e9a18a013e7604a3ad47997e4 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 12:52:58 +0200 Subject: [PATCH 17/41] replace package name from global to version --- arduino/resources/helpers.go | 4 ++-- arduino/resources/helpers_test.go | 4 ++-- cli/board/attach.go | 6 +++--- cli/board/board.go | 4 ++-- cli/board/details.go | 2 +- cli/board/list.go | 2 +- cli/board/listall.go | 4 ++-- cli/cli.go | 10 +++++++--- cli/compile/compile.go | 2 +- cli/config/config.go | 2 +- cli/config/dump.go | 2 +- cli/config/init.go | 4 ++-- cli/core/core.go | 2 +- cli/core/download.go | 4 ++-- cli/core/install.go | 4 ++-- cli/core/list.go | 2 +- cli/core/search.go | 2 +- cli/core/uninstall.go | 2 +- cli/core/update_index.go | 2 +- cli/core/upgrade.go | 4 ++-- cli/daemon/daemon.go | 2 +- cli/generatedocs/generatedocs.go | 2 +- cli/lib/download.go | 4 ++-- cli/lib/install.go | 4 ++-- cli/lib/lib.go | 4 ++-- cli/lib/list.go | 2 +- cli/lib/search.go | 2 +- cli/lib/uninstall.go | 2 +- cli/lib/update_index.go | 2 +- cli/lib/upgrade.go | 2 +- cli/root/root.go | 4 ++-- cli/sketch/new.go | 2 +- cli/sketch/sketch.go | 2 +- cli/upload/upload.go | 2 +- cli/version/version.go | 4 ++-- daemon/daemon.go | 2 +- 36 files changed, 57 insertions(+), 53 deletions(-) diff --git a/arduino/resources/helpers.go b/arduino/resources/helpers.go index 5b1ce430226..a92e638c238 100644 --- a/arduino/resources/helpers.go +++ b/arduino/resources/helpers.go @@ -82,8 +82,8 @@ func (r *DownloadResource) Download(downloadDir *paths.Path) (*downloader.Downlo // ConfigureDownloader adds additional config to the downloader helper func (r *DownloadResource) ConfigureDownloader() downloader.Config { - userAgentHeaderValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", global.GetApplication(), - global.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), global.GetCommit(), global.GetBuildDate()) + userAgentHeaderValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), + version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) downloadConfig := downloader.Config{ RequestHeaders: http.Header{ "User-Agent": []string{userAgentHeaderValue}, diff --git a/arduino/resources/helpers_test.go b/arduino/resources/helpers_test.go index 6bcc1aa3c89..4600c564c90 100644 --- a/arduino/resources/helpers_test.go +++ b/arduino/resources/helpers_test.go @@ -39,8 +39,8 @@ func (h *EchoHandler) ServeHTTP(writer http.ResponseWriter, request *http.Reques } func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { - goldUserAgentString := "User-Agent: " + fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", global.GetApplication(), - global.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), global.GetCommit(), global.GetBuildDate()) + goldUserAgentString := "User-Agent: " + fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), + version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) tmp, err := paths.MkTempDir("", "") require.NoError(t, err) diff --git a/cli/board/attach.go b/cli/board/attach.go index 79c25144c25..a316a1f852f 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -34,9 +34,9 @@ func initAttachCommand() *cobra.Command { Use: "attach | [sketchPath]", Short: "Attaches a sketch to a board.", Long: "Attaches a sketch to a board.", - Example: " " + global.GetAppName() + " board attach serial:///dev/tty/ACM0\n" + - " " + global.GetAppName() + " board attach serial:///dev/tty/ACM0 HelloWorld\n" + - " " + global.GetAppName() + " board attach arduino:samd:mkr1000", + Example: " " + version.GetAppName() + " board attach serial:///dev/tty/ACM0\n" + + " " + version.GetAppName() + " board attach serial:///dev/tty/ACM0 HelloWorld\n" + + " " + version.GetAppName() + " board attach arduino:samd:mkr1000", Args: cobra.RangeArgs(1, 2), Run: runAttachCommand, } diff --git a/cli/board/board.go b/cli/board/board.go index a18de044573..c98895344ad 100644 --- a/cli/board/board.go +++ b/cli/board/board.go @@ -29,9 +29,9 @@ func InitCommand() *cobra.Command { Short: "Arduino board commands.", Long: "Arduino board commands.", Example: " # Lists all connected boards.\n" + - " " + global.GetAppName() + " board list\n\n" + + " " + version.GetAppName() + " board list\n\n" + " # Attaches a sketch to a board.\n" + - " " + global.GetAppName() + " board attach serial:///dev/tty/ACM0 mySketch", + " " + version.GetAppName() + " board attach serial:///dev/tty/ACM0 mySketch", } boardCommand.AddCommand(initAttachCommand()) boardCommand.AddCommand(initDetailsCommand()) diff --git a/cli/board/details.go b/cli/board/details.go index 12cf549a922..7305410a69d 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -36,7 +36,7 @@ func initDetailsCommand() *cobra.Command { Use: "details ", Short: "Print details about a board.", Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.", - Example: " " + global.GetAppName() + " board details arduino:avr:nano", + Example: " " + version.GetAppName() + " board details arduino:avr:nano", Args: cobra.ExactArgs(1), Run: runDetailsCommand, } diff --git a/cli/board/list.go b/cli/board/list.go index e30faf6f8b6..cc86da93b38 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -38,7 +38,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "List connected boards.", Long: "Detects and displays a list of connected boards to the current computer.", - Example: " " + global.GetAppName() + " board list --timeout 10s", + Example: " " + version.GetAppName() + " board list --timeout 10s", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/board/listall.go b/cli/board/listall.go index 91fc8ca78e5..27a81af16d8 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -40,8 +40,8 @@ func initListAllCommand() *cobra.Command { "List all boards that have the support platform installed. You can search\n" + "for a specific board if you specify the board name", Example: "" + - " " + global.GetAppName() + " board listall\n" + - " " + global.GetAppName() + " board listall zero", + " " + version.GetAppName() + " board listall\n" + + " " + version.GetAppName() + " board listall zero", Args: cobra.ArbitraryArgs, Run: runListAllCommand, } diff --git a/cli/cli.go b/cli/cli.go index 2aeb78d9c63..bd000f55cf6 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -21,6 +21,7 @@ import ( "context" "errors" "os" + "path/filepath" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" @@ -48,8 +49,11 @@ const ( ErrBadArgument ) -// Version is the current CLI version -var Version = "0.3.6-alpha.preview" +// appName is the command line name of the Arduino CLI executable on the user system (users may change it) +var appName = filepath.Base(os.Args[0]) + +// func NewInfo(application string, versionString string, commit string) *Info { +var VersionInfo = version.NewInfo(appName) // ErrLogrus represents the logrus instance, which has the role to // log all non info messages. @@ -113,7 +117,7 @@ func CreateInstance() *rpc.Instance { for _, err := range resp.GetPlatformsIndexErrors() { formatter.PrintError(errors.New(err), "Error loading index") } - formatter.PrintErrorMessage("Launch '" + global.GetAppName() + " core update-index' to fix or download indexes.") + formatter.PrintErrorMessage("Launch '" + version.GetAppName() + " core update-index' to fix or download indexes.") os.Exit(ErrGeneric) } return resp.GetInstance() diff --git a/cli/compile/compile.go b/cli/compile/compile.go index 0789bb56d10..caede4f3054 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -36,7 +36,7 @@ func InitCommand() *cobra.Command { Use: "compile", Short: "Compiles Arduino sketches.", Long: "Compiles Arduino sketches.", - Example: " " + global.GetAppName() + " compile -b arduino:avr:uno /home/user/Arduino/MySketch", + Example: " " + version.GetAppName() + " compile -b arduino:avr:uno /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } diff --git a/cli/config/config.go b/cli/config/config.go index 0c14bd9455c..1acd6d413ca 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -27,7 +27,7 @@ func InitCommand() *cobra.Command { configCommand := &cobra.Command{ Use: "config", Short: "Arduino Configuration Commands.", - Example: " " + global.GetAppName() + " config init", + Example: " " + version.GetAppName() + " config init", } configCommand.AddCommand(initDumpCommand()) configCommand.AddCommand(initInitCommand()) diff --git a/cli/config/dump.go b/cli/config/dump.go index 756e9f8dbd2..86fc0f51c29 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -33,7 +33,7 @@ func initDumpCommand() *cobra.Command { Use: "dump", Short: "Prints the current configuration", Long: "Prints the current configuration.", - Example: " " + global.GetAppName() + " config dump", + Example: " " + version.GetAppName() + " config dump", Args: cobra.NoArgs, Run: runDumpCommand, } diff --git a/cli/config/init.go b/cli/config/init.go index b9f925cf947..a88e482e639 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -34,9 +34,9 @@ func initInitCommand() *cobra.Command { Long: "Initializes a new config file into the default location ($EXE_DIR/cli-config.yml).", Example: "" + " # Creates a config file by asking questions to the user into the default location.\n" + - " " + global.GetAppName() + " config init\n\n" + + " " + version.GetAppName() + " config init\n\n" + " # Creates a config file with default configuration into default location.\n" + - " " + global.GetAppName() + " config init --default\n", + " " + version.GetAppName() + " config init --default\n", Args: cobra.NoArgs, Run: runInitCommand, } diff --git a/cli/core/core.go b/cli/core/core.go index 528d44794f3..fe91856b318 100644 --- a/cli/core/core.go +++ b/cli/core/core.go @@ -28,7 +28,7 @@ func InitCommand() *cobra.Command { Use: "core", Short: "Arduino Core operations.", Long: "Arduino Core operations.", - Example: " " + global.GetAppName() + " core update-index", + Example: " " + version.GetAppName() + " core update-index", } coreCommand.AddCommand(initDownloadCommand()) coreCommand.AddCommand(initInstallCommand()) diff --git a/cli/core/download.go b/cli/core/download.go index a0002bd36c3..6846c4c31af 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -36,8 +36,8 @@ func initDownloadCommand() *cobra.Command { Short: "Downloads one or more cores and corresponding tool dependencies.", Long: "Downloads one or more cores and corresponding tool dependencies.", Example: "" + - " " + global.GetAppName() + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" + - " " + global.GetAppName() + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).", + " " + version.GetAppName() + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" + + " " + version.GetAppName() + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).", Args: cobra.MinimumNArgs(1), Run: runDownloadCommand, } diff --git a/cli/core/install.go b/cli/core/install.go index 8fc9d6410c7..24c61a05379 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -36,9 +36,9 @@ func initInstallCommand() *cobra.Command { Short: "Installs one or more cores and corresponding tool dependencies.", Long: "Installs one or more cores and corresponding tool dependencies.", Example: " # download the latest version of arduino SAMD core.\n" + - " " + global.GetAppName() + " core install arduino:samd\n\n" + + " " + version.GetAppName() + " core install arduino:samd\n\n" + " # download a specific version (in this case 1.6.9).\n" + - " " + global.GetAppName() + " core install arduino:samd@1.6.9", + " " + version.GetAppName() + " core install arduino:samd@1.6.9", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } diff --git a/cli/core/list.go b/cli/core/list.go index 749fab45a96..e911f2c1782 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -38,7 +38,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "Shows the list of installed platforms.", Long: "Shows the list of installed platforms.", - Example: " " + global.GetAppName() + " core list", + Example: " " + version.GetAppName() + " core list", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/core/search.go b/cli/core/search.go index 5ea4f3f9882..0adfad914f2 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -39,7 +39,7 @@ func initSearchCommand() *cobra.Command { Use: "search ", Short: "Search for a core in the package index.", Long: "Search for a core in the package index using the specified keywords.", - Example: " " + global.GetAppName() + " core search MKRZero -v", + Example: " " + version.GetAppName() + " core search MKRZero -v", Args: cobra.MinimumNArgs(1), Run: runSearchCommand, } diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 8d6867346b3..0351219e3dd 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -36,7 +36,7 @@ func initUninstallCommand() *cobra.Command { Use: "uninstall PACKAGER:ARCH ...", Short: "Uninstalls one or more cores and corresponding tool dependencies if no more used.", Long: "Uninstalls one or more cores and corresponding tool dependencies if no more used.", - Example: " " + global.GetAppName() + " core uninstall arduino:samd\n", + Example: " " + version.GetAppName() + " core uninstall arduino:samd\n", Args: cobra.MinimumNArgs(1), Run: runUninstallCommand, } diff --git a/cli/core/update_index.go b/cli/core/update_index.go index 379d95bc788..3306bb47d52 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -35,7 +35,7 @@ func initUpdateIndexCommand() *cobra.Command { Use: "update-index", Short: "Updates the index of cores.", Long: "Updates the index of cores to the latest version.", - Example: " " + global.GetAppName() + " core update-index", + Example: " " + version.GetAppName() + " core update-index", Args: cobra.NoArgs, Run: runUpdateIndexCommand, } diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 4bf0f132f00..8da5d079612 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -37,9 +37,9 @@ func initUpgradeCommand() *cobra.Command { Long: "Upgrades one or all installed platforms to the latest version.", Example: "" + " # upgrade everything to the latest version\n" + - " " + global.GetAppName() + " core upgrade\n\n" + + " " + version.GetAppName() + " core upgrade\n\n" + " # upgrade arduino:samd to the latest version\n" + - " " + global.GetAppName() + " core upgrade arduino:samd", + " " + version.GetAppName() + " core upgrade arduino:samd", Run: runUpgradeCommand, } return upgradeCommand diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 07744bf6ab3..9d90091e682 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -35,7 +35,7 @@ func InitCommand() *cobra.Command { Use: "daemon", Short: "Run as a daemon", Long: "Running as a daemon the initialization of cores and libraries is done only once.", - Example: " " + global.GetAppName() + " daemon", + Example: " " + version.GetAppName() + " daemon", Args: cobra.NoArgs, Run: runDaemonCommand, Hidden: true, diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index 41950782894..af44defd687 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -34,7 +34,7 @@ func InitCommand() *cobra.Command { Use: "generate-docs", Short: "Generates bash completion and command manpages.", Long: "Generates bash completion and command manpages.", - Example: " " + global.GetAppName() + " generate-docs bash-completions", + Example: " " + version.GetAppName() + " generate-docs bash-completions", } command.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "", "Directory where to save generated files. Default is './docs', the directory must exist.") diff --git a/cli/lib/download.go b/cli/lib/download.go index 5459ba69115..2ed41287a32 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -36,8 +36,8 @@ func initDownloadCommand() *cobra.Command { Short: "Downloads one or more libraries without installing them.", Long: "Downloads one or more libraries without installing them.", Example: "" + - " " + global.GetAppName() + " lib download AudioZero # for the latest version.\n" + - " " + global.GetAppName() + " lib download AudioZero@1.0.0 # for a specific version.", + " " + version.GetAppName() + " lib download AudioZero # for the latest version.\n" + + " " + version.GetAppName() + " lib download AudioZero@1.0.0 # for a specific version.", Args: cobra.MinimumNArgs(1), Run: runDownloadCommand, } diff --git a/cli/lib/install.go b/cli/lib/install.go index 585a710286e..2a08fd02a55 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -36,8 +36,8 @@ func initInstallCommand() *cobra.Command { Short: "Installs one of more specified libraries into the system.", Long: "Installs one or more specified libraries into the system.", Example: "" + - " " + global.GetAppName() + " lib install AudioZero # for the latest version.\n" + - " " + global.GetAppName() + " lib install AudioZero@1.0.0 # for the specific version.", + " " + version.GetAppName() + " lib install AudioZero # for the latest version.\n" + + " " + version.GetAppName() + " lib install AudioZero@1.0.0 # for the specific version.", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } diff --git a/cli/lib/lib.go b/cli/lib/lib.go index 7610aa6718e..b6f1d2f8313 100644 --- a/cli/lib/lib.go +++ b/cli/lib/lib.go @@ -29,8 +29,8 @@ func InitCommand() *cobra.Command { Short: "Arduino commands about libraries.", Long: "Arduino commands about libraries.", Example: "" + - " " + global.GetAppName() + " lib install AudioZero\n" + - " " + global.GetAppName() + " lib update-index", + " " + version.GetAppName() + " lib install AudioZero\n" + + " " + version.GetAppName() + " lib update-index", } libCommand.AddCommand(initDownloadCommand()) libCommand.AddCommand(initInstallCommand()) diff --git a/cli/lib/list.go b/cli/lib/list.go index 53faeb93e4b..48522ca2c6e 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -37,7 +37,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "Shows a list of all installed libraries.", Long: "Shows a list of all installed libraries.", - Example: " " + global.GetAppName() + " lib list", + Example: " " + version.GetAppName() + " lib list", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/lib/search.go b/cli/lib/search.go index bd9e11ce692..dabdd1eb39a 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -39,7 +39,7 @@ func initSearchCommand() *cobra.Command { Use: "search [LIBRARY_NAME]", Short: "Searchs for one or more libraries data.", Long: "Search for one or more libraries data (case insensitive search).", - Example: " " + global.GetAppName() + " lib search audio", + Example: " " + version.GetAppName() + " lib search audio", Args: cobra.ArbitraryArgs, Run: runSearchCommand, } diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index ed6ce1728bf..b61d5c0ee2e 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -36,7 +36,7 @@ func initUninstallCommand() *cobra.Command { Use: "uninstall LIBRARY_NAME(S)", Short: "Uninstalls one or more libraries.", Long: "Uninstalls one or more libraries.", - Example: " " + global.GetAppName() + " lib uninstall AudioZero", + Example: " " + version.GetAppName() + " lib uninstall AudioZero", Args: cobra.MinimumNArgs(1), Run: runUninstallCommand, } diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 27c6516671a..9af5c1b3095 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -34,7 +34,7 @@ func initUpdateIndexCommand() *cobra.Command { Use: "update-index", Short: "Updates the libraries index.", Long: "Updates the libraries index to the latest version.", - Example: " " + global.GetAppName() + " lib update-index", + Example: " " + version.GetAppName() + " lib update-index", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { instance := cli.CreateInstaceIgnorePlatformIndexErrors() diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index c2e0dd6e030..223a5b12689 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -36,7 +36,7 @@ func initUpgradeCommand() *cobra.Command { Short: "Upgrades installed libraries.", Long: "This command ungrades all installed libraries to the latest available version." + "To upgrade a single library use the 'install' command.", - Example: " " + global.GetAppName() + " lib upgrade", + Example: " " + version.GetAppName() + " lib upgrade", Args: cobra.NoArgs, Run: runUpgradeCommand, } diff --git a/cli/root/root.go b/cli/root/root.go index 63047104030..69561f2d793 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -49,7 +49,7 @@ func Init() *cobra.Command { Use: "arduino-cli", Short: "Arduino CLI.", Long: "Arduino Command Line Interface (arduino-cli).", - Example: " " + global.GetAppName() + " [flags...]", + Example: " " + version.GetAppName() + " [flags...]", PersistentPreRun: preRun, } command.PersistentFlags().BoolVar(&cli.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).") @@ -92,7 +92,7 @@ func preRun(cmd *cobra.Command, args []string) { } initConfigs() - logrus.Info(global.GetAppName() + "-" + global.GetVersion()) + logrus.Info(version.GetAppName() + "-" + version.GetVersion()) logrus.Info("Starting root command preparation (`arduino`)") switch outputFormat { case "text": diff --git a/cli/sketch/new.go b/cli/sketch/new.go index a590b26b8c7..f1396a62829 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -31,7 +31,7 @@ func initNewCommand() *cobra.Command { Use: "new", Short: "Create a new Sketch", Long: "Create a new Sketch", - Example: " " + global.GetAppName() + " sketch new MultiBlinker", + Example: " " + version.GetAppName() + " sketch new MultiBlinker", Args: cobra.ExactArgs(1), Run: runNewCommand, } diff --git a/cli/sketch/sketch.go b/cli/sketch/sketch.go index 3ef1b749689..aa090bfa485 100644 --- a/cli/sketch/sketch.go +++ b/cli/sketch/sketch.go @@ -28,7 +28,7 @@ func InitCommand() *cobra.Command { Use: "sketch", Short: "Arduino CLI Sketch Commands.", Long: "Arduino CLI Sketch Commands.", - Example: " " + global.GetAppName() + " sketch new MySketch", + Example: " " + version.GetAppName() + " sketch new MySketch", } sketchCommand.AddCommand(initNewCommand()) //sketchCommand.AddCommand(initSyncCommand()) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 5b3cd6483c5..3f116b0b9b2 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -36,7 +36,7 @@ func InitCommand() *cobra.Command { Use: "upload", Short: "Upload Arduino sketches.", Long: "Upload Arduino sketches.", - Example: " " + global.GetAppName() + " upload /home/user/Arduino/MySketch", + Example: " " + version.GetAppName() + " upload /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } diff --git a/cli/version/version.go b/cli/version/version.go index d7bd2403f72..679e02cf634 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -32,7 +32,7 @@ func InitCommand() *cobra.Command { Use: "version", Short: "Shows version number of arduino CLI.", Long: "Shows version number of arduino CLI which is installed on your system.", - Example: " " + global.GetAppName() + " version", + Example: " " + version.GetAppName() + " version", Args: cobra.NoArgs, Run: run, } @@ -47,7 +47,7 @@ type versionOutput struct { func run(cmd *cobra.Command, args []string) { res := &versionOutput{ Command: cmd.Parent().Name(), - Version: global.GetVersion(), + Version: version.GetVersion(), } if cli.OutputJSONOrElse(res) { fmt.Printf("%s version %s\n", res.Command, res.Version) diff --git a/daemon/daemon.go b/daemon/daemon.go index 012931547e4..80e08b49197 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -121,7 +121,7 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In } func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq) (*rpc.VersionResp, error) { - return &rpc.VersionResp{Version: global.GetVersion()}, nil + return &rpc.VersionResp{Version: version.GetVersion()}, nil } func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error { From 2a8b48e8afdf1c982306f949f659d61a73370adc Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 15:22:03 +0200 Subject: [PATCH 18/41] solve package name clash for version and cli/version --- cli/root/root.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/root/root.go b/cli/root/root.go index 69561f2d793..93f2f0d5e50 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -35,8 +35,8 @@ import ( "github.com/arduino/arduino-cli/cli/version" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" - "github.com/arduino/arduino-cli/version" - paths "github.com/arduino/go-paths-helper" + ver "github.com/arduino/arduino-cli/version" + "github.com/arduino/go-paths-helper" "github.com/mattn/go-colorable" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -49,7 +49,7 @@ func Init() *cobra.Command { Use: "arduino-cli", Short: "Arduino CLI.", Long: "Arduino Command Line Interface (arduino-cli).", - Example: " " + version.GetAppName() + " [flags...]", + Example: " " + ver.GetAppName() + " [flags...]", PersistentPreRun: preRun, } command.PersistentFlags().BoolVar(&cli.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).") @@ -92,7 +92,7 @@ func preRun(cmd *cobra.Command, args []string) { } initConfigs() - logrus.Info(version.GetAppName() + "-" + version.GetVersion()) + logrus.Info(ver.GetAppName() + "-" + ver.GetVersion()) logrus.Info("Starting root command preparation (`arduino`)") switch outputFormat { case "text": From 7415b9ad580ad7b7d995952afa4af74eeb6ecd61 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 15:46:28 +0200 Subject: [PATCH 19/41] replace application name getter with VersionInfo.Application field having removed cli login,logout,validate --- cli/board/attach.go | 7 +++---- cli/board/board.go | 6 +++--- cli/board/details.go | 3 +-- cli/board/list.go | 3 +-- cli/board/listall.go | 5 ++--- cli/cli.go | 2 +- cli/compile/compile.go | 3 +-- cli/config/config.go | 4 ++-- cli/config/dump.go | 3 +-- cli/config/init.go | 5 ++--- cli/core/core.go | 4 ++-- cli/core/download.go | 5 ++--- cli/core/install.go | 5 ++--- cli/core/list.go | 3 +-- cli/core/search.go | 3 +-- cli/core/uninstall.go | 3 +-- cli/core/update_index.go | 3 +-- cli/core/upgrade.go | 5 ++--- cli/daemon/daemon.go | 4 ++-- cli/generatedocs/generatedocs.go | 3 +-- cli/lib/download.go | 5 ++--- cli/lib/install.go | 5 ++--- cli/lib/lib.go | 6 +++--- cli/lib/list.go | 3 +-- cli/lib/search.go | 3 +-- cli/lib/uninstall.go | 3 +-- cli/lib/update_index.go | 3 +-- cli/lib/upgrade.go | 3 +-- cli/sketch/new.go | 3 +-- cli/sketch/sketch.go | 4 ++-- cli/upload/upload.go | 3 +-- cli/version/version.go | 2 +- 32 files changed, 49 insertions(+), 73 deletions(-) diff --git a/cli/board/attach.go b/cli/board/attach.go index a316a1f852f..a1fc5563a79 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -34,9 +33,9 @@ func initAttachCommand() *cobra.Command { Use: "attach | [sketchPath]", Short: "Attaches a sketch to a board.", Long: "Attaches a sketch to a board.", - Example: " " + version.GetAppName() + " board attach serial:///dev/tty/ACM0\n" + - " " + version.GetAppName() + " board attach serial:///dev/tty/ACM0 HelloWorld\n" + - " " + version.GetAppName() + " board attach arduino:samd:mkr1000", + Example: " " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0\n" + + " " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0 HelloWorld\n" + + " " + cli.VersionInfo.Application + " board attach arduino:samd:mkr1000", Args: cobra.RangeArgs(1, 2), Run: runAttachCommand, } diff --git a/cli/board/board.go b/cli/board/board.go index c98895344ad..5a29328ac32 100644 --- a/cli/board/board.go +++ b/cli/board/board.go @@ -18,7 +18,7 @@ package board import ( - "github.com/arduino/arduino-cli/version" + "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" ) @@ -29,9 +29,9 @@ func InitCommand() *cobra.Command { Short: "Arduino board commands.", Long: "Arduino board commands.", Example: " # Lists all connected boards.\n" + - " " + version.GetAppName() + " board list\n\n" + + " " + cli.VersionInfo.Application + " board list\n\n" + " # Attaches a sketch to a board.\n" + - " " + version.GetAppName() + " board attach serial:///dev/tty/ACM0 mySketch", + " " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0 mySketch", } boardCommand.AddCommand(initAttachCommand()) boardCommand.AddCommand(initDetailsCommand()) diff --git a/cli/board/details.go b/cli/board/details.go index 7305410a69d..5239a9be999 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -27,7 +27,6 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -36,7 +35,7 @@ func initDetailsCommand() *cobra.Command { Use: "details ", Short: "Print details about a board.", Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.", - Example: " " + version.GetAppName() + " board details arduino:avr:nano", + Example: " " + cli.VersionInfo.Application + " board details arduino:avr:nano", Args: cobra.ExactArgs(1), Run: runDetailsCommand, } diff --git a/cli/board/list.go b/cli/board/list.go index cc86da93b38..280c0eb6db8 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -29,7 +29,6 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -38,7 +37,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "List connected boards.", Long: "Detects and displays a list of connected boards to the current computer.", - Example: " " + version.GetAppName() + " board list --timeout 10s", + Example: " " + cli.VersionInfo.Application + " board list --timeout 10s", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/board/listall.go b/cli/board/listall.go index 27a81af16d8..533d33eeda3 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -28,7 +28,6 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -40,8 +39,8 @@ func initListAllCommand() *cobra.Command { "List all boards that have the support platform installed. You can search\n" + "for a specific board if you specify the board name", Example: "" + - " " + version.GetAppName() + " board listall\n" + - " " + version.GetAppName() + " board listall zero", + " " + cli.VersionInfo.Application + " board listall\n" + + " " + cli.VersionInfo.Application + " board listall zero", Args: cobra.ArbitraryArgs, Run: runListAllCommand, } diff --git a/cli/cli.go b/cli/cli.go index bd000f55cf6..493a369bc10 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -117,7 +117,7 @@ func CreateInstance() *rpc.Instance { for _, err := range resp.GetPlatformsIndexErrors() { formatter.PrintError(errors.New(err), "Error loading index") } - formatter.PrintErrorMessage("Launch '" + version.GetAppName() + " core update-index' to fix or download indexes.") + formatter.PrintErrorMessage("Launch '" + VersionInfo.Application + " core update-index' to fix or download indexes.") os.Exit(ErrGeneric) } return resp.GetInstance() diff --git a/cli/compile/compile.go b/cli/compile/compile.go index caede4f3054..d01274dce98 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/compile" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" ) @@ -36,7 +35,7 @@ func InitCommand() *cobra.Command { Use: "compile", Short: "Compiles Arduino sketches.", Long: "Compiles Arduino sketches.", - Example: " " + version.GetAppName() + " compile -b arduino:avr:uno /home/user/Arduino/MySketch", + Example: " " + cli.VersionInfo.Application + " compile -b arduino:avr:uno /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } diff --git a/cli/config/config.go b/cli/config/config.go index 1acd6d413ca..a03e0a0b083 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -18,7 +18,7 @@ package config import ( - "github.com/arduino/arduino-cli/version" + "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" ) @@ -27,7 +27,7 @@ func InitCommand() *cobra.Command { configCommand := &cobra.Command{ Use: "config", Short: "Arduino Configuration Commands.", - Example: " " + version.GetAppName() + " config init", + Example: " " + cli.VersionInfo.Application + " config init", } configCommand.AddCommand(initDumpCommand()) configCommand.AddCommand(initInitCommand()) diff --git a/cli/config/dump.go b/cli/config/dump.go index 86fc0f51c29..c90daf246d6 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -23,7 +23,6 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -33,7 +32,7 @@ func initDumpCommand() *cobra.Command { Use: "dump", Short: "Prints the current configuration", Long: "Prints the current configuration.", - Example: " " + version.GetAppName() + " config dump", + Example: " " + cli.VersionInfo.Application + " config dump", Args: cobra.NoArgs, Run: runDumpCommand, } diff --git a/cli/config/init.go b/cli/config/init.go index a88e482e639..c2068c9e3c8 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -22,7 +22,6 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -34,9 +33,9 @@ func initInitCommand() *cobra.Command { Long: "Initializes a new config file into the default location ($EXE_DIR/cli-config.yml).", Example: "" + " # Creates a config file by asking questions to the user into the default location.\n" + - " " + version.GetAppName() + " config init\n\n" + + " " + cli.VersionInfo.Application + " config init\n\n" + " # Creates a config file with default configuration into default location.\n" + - " " + version.GetAppName() + " config init --default\n", + " " + cli.VersionInfo.Application + " config init --default\n", Args: cobra.NoArgs, Run: runInitCommand, } diff --git a/cli/core/core.go b/cli/core/core.go index fe91856b318..b8aa1f297c7 100644 --- a/cli/core/core.go +++ b/cli/core/core.go @@ -18,7 +18,7 @@ package core import ( - "github.com/arduino/arduino-cli/version" + "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" ) @@ -28,7 +28,7 @@ func InitCommand() *cobra.Command { Use: "core", Short: "Arduino Core operations.", Long: "Arduino Core operations.", - Example: " " + version.GetAppName() + " core update-index", + Example: " " + cli.VersionInfo.Application + " core update-index", } coreCommand.AddCommand(initDownloadCommand()) coreCommand.AddCommand(initInstallCommand()) diff --git a/cli/core/download.go b/cli/core/download.go index 6846c4c31af..8e043500a80 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -36,8 +35,8 @@ func initDownloadCommand() *cobra.Command { Short: "Downloads one or more cores and corresponding tool dependencies.", Long: "Downloads one or more cores and corresponding tool dependencies.", Example: "" + - " " + version.GetAppName() + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" + - " " + version.GetAppName() + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).", + " " + cli.VersionInfo.Application + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" + + " " + cli.VersionInfo.Application + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).", Args: cobra.MinimumNArgs(1), Run: runDownloadCommand, } diff --git a/cli/core/install.go b/cli/core/install.go index 24c61a05379..677e65d3c51 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -36,9 +35,9 @@ func initInstallCommand() *cobra.Command { Short: "Installs one or more cores and corresponding tool dependencies.", Long: "Installs one or more cores and corresponding tool dependencies.", Example: " # download the latest version of arduino SAMD core.\n" + - " " + version.GetAppName() + " core install arduino:samd\n\n" + + " " + cli.VersionInfo.Application + " core install arduino:samd\n\n" + " # download a specific version (in this case 1.6.9).\n" + - " " + version.GetAppName() + " core install arduino:samd@1.6.9", + " " + cli.VersionInfo.Application + " core install arduino:samd@1.6.9", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } diff --git a/cli/core/list.go b/cli/core/list.go index e911f2c1782..91efcd6c4cf 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -28,7 +28,6 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -38,7 +37,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "Shows the list of installed platforms.", Long: "Shows the list of installed platforms.", - Example: " " + version.GetAppName() + " core list", + Example: " " + cli.VersionInfo.Application + " core list", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/core/search.go b/cli/core/search.go index 0adfad914f2..0f752189357 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -29,7 +29,6 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -39,7 +38,7 @@ func initSearchCommand() *cobra.Command { Use: "search ", Short: "Search for a core in the package index.", Long: "Search for a core in the package index using the specified keywords.", - Example: " " + version.GetAppName() + " core search MKRZero -v", + Example: " " + cli.VersionInfo.Application + " core search MKRZero -v", Args: cobra.MinimumNArgs(1), Run: runSearchCommand, } diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 0351219e3dd..90e0472731d 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -26,7 +26,6 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -36,7 +35,7 @@ func initUninstallCommand() *cobra.Command { Use: "uninstall PACKAGER:ARCH ...", Short: "Uninstalls one or more cores and corresponding tool dependencies if no more used.", Long: "Uninstalls one or more cores and corresponding tool dependencies if no more used.", - Example: " " + version.GetAppName() + " core uninstall arduino:samd\n", + Example: " " + cli.VersionInfo.Application + " core uninstall arduino:samd\n", Args: cobra.MinimumNArgs(1), Run: runUninstallCommand, } diff --git a/cli/core/update_index.go b/cli/core/update_index.go index 3306bb47d52..13d832343f1 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -35,7 +34,7 @@ func initUpdateIndexCommand() *cobra.Command { Use: "update-index", Short: "Updates the index of cores.", Long: "Updates the index of cores to the latest version.", - Example: " " + version.GetAppName() + " core update-index", + Example: " " + cli.VersionInfo.Application + " core update-index", Args: cobra.NoArgs, Run: runUpdateIndexCommand, } diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 8da5d079612..aa5a2a0729e 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -37,9 +36,9 @@ func initUpgradeCommand() *cobra.Command { Long: "Upgrades one or all installed platforms to the latest version.", Example: "" + " # upgrade everything to the latest version\n" + - " " + version.GetAppName() + " core upgrade\n\n" + + " " + cli.VersionInfo.Application + " core upgrade\n\n" + " # upgrade arduino:samd to the latest version\n" + - " " + version.GetAppName() + " core upgrade arduino:samd", + " " + cli.VersionInfo.Application + " core upgrade arduino:samd", Run: runUpgradeCommand, } return upgradeCommand diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 9d90091e682..f85b9b2bc10 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -22,9 +22,9 @@ import ( "log" "net" + "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/daemon" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" "google.golang.org/grpc" ) @@ -35,7 +35,7 @@ func InitCommand() *cobra.Command { Use: "daemon", Short: "Run as a daemon", Long: "Running as a daemon the initialization of cores and libraries is done only once.", - Example: " " + version.GetAppName() + " daemon", + Example: " " + cli.VersionInfo.Application + " daemon", Args: cobra.NoArgs, Run: runDaemonCommand, Hidden: true, diff --git a/cli/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go index af44defd687..000537b811f 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -22,7 +22,6 @@ import ( "path/filepath" "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" @@ -34,7 +33,7 @@ func InitCommand() *cobra.Command { Use: "generate-docs", Short: "Generates bash completion and command manpages.", Long: "Generates bash completion and command manpages.", - Example: " " + version.GetAppName() + " generate-docs bash-completions", + Example: " " + cli.VersionInfo.Application + " generate-docs bash-completions", } command.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "", "Directory where to save generated files. Default is './docs', the directory must exist.") diff --git a/cli/lib/download.go b/cli/lib/download.go index 2ed41287a32..28c6c38a346 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -26,7 +26,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -36,8 +35,8 @@ func initDownloadCommand() *cobra.Command { Short: "Downloads one or more libraries without installing them.", Long: "Downloads one or more libraries without installing them.", Example: "" + - " " + version.GetAppName() + " lib download AudioZero # for the latest version.\n" + - " " + version.GetAppName() + " lib download AudioZero@1.0.0 # for a specific version.", + " " + cli.VersionInfo.Application + " lib download AudioZero # for the latest version.\n" + + " " + cli.VersionInfo.Application + " lib download AudioZero@1.0.0 # for a specific version.", Args: cobra.MinimumNArgs(1), Run: runDownloadCommand, } diff --git a/cli/lib/install.go b/cli/lib/install.go index 2a08fd02a55..1fcc6f893c9 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -26,7 +26,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -36,8 +35,8 @@ func initInstallCommand() *cobra.Command { Short: "Installs one of more specified libraries into the system.", Long: "Installs one or more specified libraries into the system.", Example: "" + - " " + version.GetAppName() + " lib install AudioZero # for the latest version.\n" + - " " + version.GetAppName() + " lib install AudioZero@1.0.0 # for the specific version.", + " " + cli.VersionInfo.Application + " lib install AudioZero # for the latest version.\n" + + " " + cli.VersionInfo.Application + " lib install AudioZero@1.0.0 # for the specific version.", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } diff --git a/cli/lib/lib.go b/cli/lib/lib.go index b6f1d2f8313..148ddd1da30 100644 --- a/cli/lib/lib.go +++ b/cli/lib/lib.go @@ -18,7 +18,7 @@ package lib import ( - "github.com/arduino/arduino-cli/version" + "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" ) @@ -29,8 +29,8 @@ func InitCommand() *cobra.Command { Short: "Arduino commands about libraries.", Long: "Arduino commands about libraries.", Example: "" + - " " + version.GetAppName() + " lib install AudioZero\n" + - " " + version.GetAppName() + " lib update-index", + " " + cli.VersionInfo.Application + " lib install AudioZero\n" + + " " + cli.VersionInfo.Application + " lib update-index", } libCommand.AddCommand(initDownloadCommand()) libCommand.AddCommand(initInstallCommand()) diff --git a/cli/lib/list.go b/cli/lib/list.go index 48522ca2c6e..5766ad19fa8 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/gosuri/uitable" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -37,7 +36,7 @@ func initListCommand() *cobra.Command { Use: "list", Short: "Shows a list of all installed libraries.", Long: "Shows a list of all installed libraries.", - Example: " " + version.GetAppName() + " lib list", + Example: " " + cli.VersionInfo.Application + " lib list", Args: cobra.NoArgs, Run: runListCommand, } diff --git a/cli/lib/search.go b/cli/lib/search.go index dabdd1eb39a..674f018eb01 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -28,7 +28,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" semver "go.bug.st/relaxed-semver" @@ -39,7 +38,7 @@ func initSearchCommand() *cobra.Command { Use: "search [LIBRARY_NAME]", Short: "Searchs for one or more libraries data.", Long: "Search for one or more libraries data (case insensitive search).", - Example: " " + version.GetAppName() + " lib search audio", + Example: " " + cli.VersionInfo.Application + " lib search audio", Args: cobra.ArbitraryArgs, Run: runSearchCommand, } diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index b61d5c0ee2e..6c38a93c9a6 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -26,7 +26,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -36,7 +35,7 @@ func initUninstallCommand() *cobra.Command { Use: "uninstall LIBRARY_NAME(S)", Short: "Uninstalls one or more libraries.", Long: "Uninstalls one or more libraries.", - Example: " " + version.GetAppName() + " lib uninstall AudioZero", + Example: " " + cli.VersionInfo.Application + " lib uninstall AudioZero", Args: cobra.MinimumNArgs(1), Run: runUninstallCommand, } diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 9af5c1b3095..6c7f22a3b62 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -34,7 +33,7 @@ func initUpdateIndexCommand() *cobra.Command { Use: "update-index", Short: "Updates the libraries index.", Long: "Updates the libraries index to the latest version.", - Example: " " + version.GetAppName() + " lib update-index", + Example: " " + cli.VersionInfo.Application + " lib update-index", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { instance := cli.CreateInstaceIgnorePlatformIndexErrors() diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index 223a5b12689..122f0073faa 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -24,7 +24,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/net/context" @@ -36,7 +35,7 @@ func initUpgradeCommand() *cobra.Command { Short: "Upgrades installed libraries.", Long: "This command ungrades all installed libraries to the latest available version." + "To upgrade a single library use the 'install' command.", - Example: " " + version.GetAppName() + " lib upgrade", + Example: " " + cli.VersionInfo.Application + " lib upgrade", Args: cobra.NoArgs, Run: runUpgradeCommand, } diff --git a/cli/sketch/new.go b/cli/sketch/new.go index f1396a62829..7ed9f20e739 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -22,7 +22,6 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -31,7 +30,7 @@ func initNewCommand() *cobra.Command { Use: "new", Short: "Create a new Sketch", Long: "Create a new Sketch", - Example: " " + version.GetAppName() + " sketch new MultiBlinker", + Example: " " + cli.VersionInfo.Application + " sketch new MultiBlinker", Args: cobra.ExactArgs(1), Run: runNewCommand, } diff --git a/cli/sketch/sketch.go b/cli/sketch/sketch.go index aa090bfa485..2c735778c52 100644 --- a/cli/sketch/sketch.go +++ b/cli/sketch/sketch.go @@ -18,7 +18,7 @@ package sketch import ( - "github.com/arduino/arduino-cli/version" + "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" ) @@ -28,7 +28,7 @@ func InitCommand() *cobra.Command { Use: "sketch", Short: "Arduino CLI Sketch Commands.", Long: "Arduino CLI Sketch Commands.", - Example: " " + version.GetAppName() + " sketch new MySketch", + Example: " " + cli.VersionInfo.Application + " sketch new MySketch", } sketchCommand.AddCommand(initNewCommand()) //sketchCommand.AddCommand(initSyncCommand()) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 3f116b0b9b2..23f264dab70 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" ) @@ -36,7 +35,7 @@ func InitCommand() *cobra.Command { Use: "upload", Short: "Upload Arduino sketches.", Long: "Upload Arduino sketches.", - Example: " " + version.GetAppName() + " upload /home/user/Arduino/MySketch", + Example: " " + cli.VersionInfo.Application + " upload /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } diff --git a/cli/version/version.go b/cli/version/version.go index 679e02cf634..1ea7c43d8da 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -32,7 +32,7 @@ func InitCommand() *cobra.Command { Use: "version", Short: "Shows version number of arduino CLI.", Long: "Shows version number of arduino CLI which is installed on your system.", - Example: " " + version.GetAppName() + " version", + Example: " " + cli.VersionInfo.Application + " version", Args: cobra.NoArgs, Run: run, } From cb3a5723f0aba8b62555a115cc105b145ba6fb4e Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Thu, 6 Jun 2019 17:24:20 +0200 Subject: [PATCH 20/41] search and replace version string getter with VersionInfo.VersionString field --- cli/version/version.go | 3 +-- daemon/daemon.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/version/version.go b/cli/version/version.go index 1ea7c43d8da..a9894d48802 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -22,7 +22,6 @@ import ( "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" ) @@ -47,7 +46,7 @@ type versionOutput struct { func run(cmd *cobra.Command, args []string) { res := &versionOutput{ Command: cmd.Parent().Name(), - Version: version.GetVersion(), + Version: cli.VersionInfo.VersionString, } if cli.OutputJSONOrElse(res) { fmt.Printf("%s version %s\n", res.Command, res.Version) diff --git a/daemon/daemon.go b/daemon/daemon.go index 80e08b49197..a2a65a04158 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -26,6 +26,7 @@ import ( "log" "net" + "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands/board" "github.com/arduino/arduino-cli/commands/compile" @@ -33,7 +34,6 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" "google.golang.org/grpc" ) @@ -121,7 +121,7 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In } func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq) (*rpc.VersionResp, error) { - return &rpc.VersionResp{Version: version.GetVersion()}, nil + return &rpc.VersionResp{Version: cli.VersionInfo.VersionString}, nil } func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error { From 2bccd1f63dc2727fb40d0b2f39c38ff25126e5a4 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 09:50:26 +0200 Subject: [PATCH 21/41] implement empty http.Header struct propagation from cli to resources --- arduino/cores/packagemanager/download.go | 9 +++++---- arduino/resources/resources_test.go | 5 +++-- cli/board/attach.go | 3 ++- cli/board/details.go | 3 ++- cli/board/list.go | 3 ++- cli/board/listall.go | 3 ++- cli/cli.go | 17 +++++++++-------- cli/compile/compile.go | 3 ++- cli/core/download.go | 7 +++++-- cli/core/install.go | 5 +++-- cli/core/list.go | 3 ++- cli/core/search.go | 3 ++- cli/core/uninstall.go | 3 ++- cli/core/update_index.go | 3 ++- cli/core/upgrade.go | 6 ++++-- cli/lib/download.go | 5 +++-- cli/lib/install.go | 5 +++-- cli/lib/list.go | 3 ++- cli/lib/search.go | 3 ++- cli/lib/uninstall.go | 3 ++- cli/lib/update_index.go | 3 ++- cli/lib/upgrade.go | 5 +++-- cli/upload/upload.go | 3 ++- commands/bundled_tools.go | 5 +++-- commands/core/download.go | 15 ++++++++------- commands/core/install.go | 11 ++++++----- commands/core/upgrade.go | 9 +++++---- commands/instances.go | 15 ++++++++------- commands/lib/download.go | 9 +++++---- commands/lib/install.go | 5 +++-- commands/lib/upgrade.go | 5 +++-- 31 files changed, 107 insertions(+), 73 deletions(-) diff --git a/arduino/cores/packagemanager/download.go b/arduino/cores/packagemanager/download.go index b62488c8013..15c4b58916a 100644 --- a/arduino/cores/packagemanager/download.go +++ b/arduino/cores/packagemanager/download.go @@ -19,6 +19,7 @@ package packagemanager import ( "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/cores" "go.bug.st/downloader" @@ -102,16 +103,16 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc // DownloadToolRelease downloads a ToolRelease. If the tool is already downloaded a nil Downloader // is returned. -func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease) (*downloader.Downloader, error) { +func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, downloaderHeaders http.Header) (*downloader.Downloader, error) { resource := tool.GetCompatibleFlavour() if resource == nil { return nil, fmt.Errorf("tool not available for your OS") } - return resource.Download(pm.DownloadDir) + return resource.Download(pm.DownloadDir, downloaderHeaders) } // DownloadPlatformRelease downloads a PlatformRelease. If the platform is already downloaded a // nil Downloader is returned. -func (pm *PackageManager) DownloadPlatformRelease(platform *cores.PlatformRelease) (*downloader.Downloader, error) { - return platform.Resource.Download(pm.DownloadDir) +func (pm *PackageManager) DownloadPlatformRelease(platform *cores.PlatformRelease, downloaderHeaders http.Header) (*downloader.Downloader, error) { + return platform.Resource.Download(pm.DownloadDir, downloaderHeaders) } diff --git a/arduino/resources/resources_test.go b/arduino/resources/resources_test.go index 058e8959c0b..82404b30d54 100644 --- a/arduino/resources/resources_test.go +++ b/arduino/resources/resources_test.go @@ -20,6 +20,7 @@ package resources import ( "crypto" "encoding/hex" + "net/http" "testing" paths "github.com/arduino/go-paths-helper" @@ -43,7 +44,7 @@ func TestDownloadAndChecksums(t *testing.T) { require.NoError(t, err) downloadAndTestChecksum := func() { - d, err := r.Download(tmp) + d, err := r.Download(tmp, http.Header{}) require.NoError(t, err) err = d.Run() require.NoError(t, err) @@ -59,7 +60,7 @@ func TestDownloadAndChecksums(t *testing.T) { downloadAndTestChecksum() // Download with cached file - d, err := r.Download(tmp) + d, err := r.Download(tmp, http.Header{}) require.NoError(t, err) require.Nil(t, d) diff --git a/cli/board/attach.go b/cli/board/attach.go index a1fc5563a79..4887829b2b1 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -19,6 +19,7 @@ package board import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -49,7 +50,7 @@ var attachFlags struct { } func runAttachCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) var path string if len(args) > 0 { path = args[1] diff --git a/cli/board/details.go b/cli/board/details.go index 5239a9be999..a41c09d61cf 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -43,7 +44,7 @@ func initDetailsCommand() *cobra.Command { } func runDetailsCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) res, err := board.Details(context.Background(), &rpc.BoardDetailsReq{ Instance: instance, diff --git a/cli/board/list.go b/cli/board/list.go index 280c0eb6db8..74b96ed428a 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "net/http" "os" "sort" "time" @@ -53,7 +54,7 @@ var listFlags struct { // runListCommand detects and lists the connected arduino boards func runListCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) if timeout, err := time.ParseDuration(listFlags.timeout); err != nil { formatter.PrintError(err, "Invalid timeout.") diff --git a/cli/board/listall.go b/cli/board/listall.go index 533d33eeda3..131c559c9bd 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -20,6 +20,7 @@ package board import ( "context" "fmt" + "net/http" "os" "sort" @@ -49,7 +50,7 @@ func initListAllCommand() *cobra.Command { // runListAllCommand list all installed boards func runListAllCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) list, err := board.ListAll(context.Background(), &rpc.BoardListAllReq{ Instance: instance, diff --git a/cli/cli.go b/cli/cli.go index 493a369bc10..ddef28cd47e 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -20,6 +20,7 @@ package cli import ( "context" "errors" + "net/http" "os" "path/filepath" @@ -84,10 +85,10 @@ func packageManagerInitReq() *rpc.InitReq { return &rpc.InitReq{Configuration: conf} } -func InitInstance() *rpc.InitResp { +func InitInstance(downloaderHeaders http.Header) *rpc.InitResp { logrus.Info("Initializing package manager") req := packageManagerInitReq() - resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress()) + resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress(), downloaderHeaders) if err != nil { formatter.PrintError(err, "Error initializing package manager") os.Exit(ErrGeneric) @@ -111,8 +112,8 @@ func InitInstance() *rpc.InitResp { } // CreateInstance creates and return an instance of the Arduino Core engine -func CreateInstance() *rpc.Instance { - resp := InitInstance() +func CreateInstance(downloaderHeaders http.Header) *rpc.Instance { + resp := InitInstance(downloaderHeaders) if resp.GetPlatformsIndexErrors() != nil { for _, err := range resp.GetPlatformsIndexErrors() { formatter.PrintError(errors.New(err), "Error loading index") @@ -125,14 +126,14 @@ func CreateInstance() *rpc.Instance { // CreateInstaceIgnorePlatformIndexErrors creates and return an instance of the // Arduino Core Engine, but won't stop on platforms index loading errors. -func CreateInstaceIgnorePlatformIndexErrors() *rpc.Instance { - return InitInstance().GetInstance() +func CreateInstaceIgnorePlatformIndexErrors(downloaderHeaders http.Header) *rpc.Instance { + return InitInstance(downloaderHeaders).GetInstance() } // InitPackageAndLibraryManager initializes the PackageManager and the // LibaryManager with the default configuration. (DEPRECATED) -func InitPackageAndLibraryManager() (*packagemanager.PackageManager, *librariesmanager.LibrariesManager) { - resp := InitInstance() +func InitPackageAndLibraryManager(downloaderHeaders http.Header) (*packagemanager.PackageManager, *librariesmanager.LibrariesManager) { + resp := InitInstance(downloaderHeaders) return commands.GetPackageManager(resp), commands.GetLibraryManager(resp) } diff --git a/cli/compile/compile.go b/cli/compile/compile.go index d01274dce98..55f9d98bf1c 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -19,6 +19,7 @@ package compile import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -90,7 +91,7 @@ var flags struct { } func run(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) var path *paths.Path if len(args) > 0 { diff --git a/cli/core/download.go b/cli/core/download.go index 8e043500a80..8983b68c532 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -19,6 +19,7 @@ package core import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -44,7 +45,7 @@ func initDownloadCommand() *cobra.Command { } func runDownloadCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) logrus.Info("Executing `arduino core download`") platformsRefs := parsePlatformReferenceArgs(args) @@ -54,7 +55,9 @@ func runDownloadCommand(cmd *cobra.Command, args []string) { PlatformPackage: platformRef.Package, Architecture: platformRef.Architecture, Version: platformRef.Version, - }, cli.OutputProgressBar()) + }, cli.OutputProgressBar(), + http.Header{}, + ) if err != nil { formatter.PrintError(err, "Error downloading "+args[i]) os.Exit(cli.ErrNetwork) diff --git a/cli/core/install.go b/cli/core/install.go index 677e65d3c51..9dcad5c0866 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -19,6 +19,7 @@ package core import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -45,7 +46,7 @@ func initInstallCommand() *cobra.Command { } func runInstallCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) logrus.Info("Executing `arduino core install`") platformsRefs := parsePlatformReferenceArgs(args) @@ -56,7 +57,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) { PlatformPackage: platformRef.Package, Architecture: platformRef.Architecture, Version: platformRef.Version, - }, cli.OutputProgressBar(), cli.OutputTaskProgress()) + }, cli.OutputProgressBar(), cli.OutputTaskProgress(), http.Header{}) if err != nil { formatter.PrintError(err, "Error during install") os.Exit(cli.ErrGeneric) diff --git a/cli/core/list.go b/cli/core/list.go index 91efcd6c4cf..eb6a8e9fcd6 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -20,6 +20,7 @@ package core import ( "context" "fmt" + "net/http" "os" "sort" @@ -50,7 +51,7 @@ var listFlags struct { } func runListCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) logrus.Info("Executing `arduino core list`") resp, err := core.PlatformList(context.Background(), &rpc.PlatformListReq{ diff --git a/cli/core/search.go b/cli/core/search.go index 0f752189357..c2edef92cba 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -20,6 +20,7 @@ package core import ( "context" "fmt" + "net/http" "os" "sort" "strings" @@ -46,7 +47,7 @@ func initSearchCommand() *cobra.Command { } func runSearchCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) logrus.Info("Executing `arduino core search`") arguments := strings.ToLower(strings.Join(args, " ")) diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 90e0472731d..65ef5c45b49 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -19,6 +19,7 @@ package core import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -42,7 +43,7 @@ func initUninstallCommand() *cobra.Command { } func runUninstallCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) logrus.Info("Executing `arduino core uninstall`") platformsRefs := parsePlatformReferenceArgs(args) diff --git a/cli/core/update_index.go b/cli/core/update_index.go index 13d832343f1..ebc2e03506b 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -19,6 +19,7 @@ package core import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -42,7 +43,7 @@ func initUpdateIndexCommand() *cobra.Command { } func runUpdateIndexCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) logrus.Info("Executing `arduino core update-index`") _, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{ diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index aa5a2a0729e..2770a0a36ff 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -19,6 +19,7 @@ package core import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -45,7 +46,7 @@ func initUpgradeCommand() *cobra.Command { } func runUpgradeCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) logrus.Info("Executing `arduino core upgrade`") platformsRefs := parsePlatformReferenceArgs(args) @@ -60,7 +61,8 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) { Instance: instance, PlatformPackage: platformRef.Package, Architecture: platformRef.Architecture, - }, cli.OutputProgressBar(), cli.OutputTaskProgress()) + }, cli.OutputProgressBar(), cli.OutputTaskProgress(), + http.Header{}) if err != nil { formatter.PrintError(err, "Error during upgrade") os.Exit(cli.ErrGeneric) diff --git a/cli/lib/download.go b/cli/lib/download.go index 28c6c38a346..c741ff207f3 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -19,6 +19,7 @@ package lib import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -44,7 +45,7 @@ func initDownloadCommand() *cobra.Command { } func runDownloadCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) pairs, err := librariesindex.ParseArgs(args) if err != nil { formatter.PrintError(err, "Arguments error") @@ -55,7 +56,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) { Instance: instance, Name: library.Name, Version: library.Version.String(), - }, cli.OutputProgressBar()) + }, cli.OutputProgressBar(), http.Header{}) if err != nil { formatter.PrintError(err, "Error downloading "+library.String()) os.Exit(cli.ErrNetwork) diff --git a/cli/lib/install.go b/cli/lib/install.go index 1fcc6f893c9..527a9c8dc03 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -19,6 +19,7 @@ package lib import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -44,7 +45,7 @@ func initInstallCommand() *cobra.Command { } func runInstallCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) refs, err := librariesindex.ParseArgs(args) if err != nil { formatter.PrintError(err, "Arguments error") @@ -55,7 +56,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) { Instance: instance, Name: library.Name, Version: library.Version.String(), - }, cli.OutputProgressBar(), cli.OutputTaskProgress()) + }, cli.OutputProgressBar(), cli.OutputTaskProgress(), http.Header{}) if err != nil { formatter.PrintError(err, "Error installing "+library.String()) os.Exit(cli.ErrGeneric) diff --git a/cli/lib/list.go b/cli/lib/list.go index 5766ad19fa8..90995f11b32 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -19,6 +19,7 @@ package lib import ( "fmt" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -51,7 +52,7 @@ var listFlags struct { } func runListCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) logrus.Info("Listing") res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{ diff --git a/cli/lib/search.go b/cli/lib/search.go index 674f018eb01..f9a5a525bf8 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -20,6 +20,7 @@ package lib import ( "context" "fmt" + "net/http" "os" "sort" "strings" @@ -51,7 +52,7 @@ var searchFlags struct { } func runSearchCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) logrus.Info("Executing `arduino lib search`") searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchReq{ Instance: instance, diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index 6c38a93c9a6..c08b8555cb9 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -19,6 +19,7 @@ package lib import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -45,7 +46,7 @@ func initUninstallCommand() *cobra.Command { func runUninstallCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino lib uninstall`") - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) libRefs, err := librariesindex.ParseArgs(args) if err != nil { formatter.PrintError(err, "Arguments error") diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index 6c7f22a3b62..a8f4df25d85 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -19,6 +19,7 @@ package lib import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -36,7 +37,7 @@ func initUpdateIndexCommand() *cobra.Command { Example: " " + cli.VersionInfo.Application + " lib update-index", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{ Instance: instance, }, cli.OutputProgressBar()) diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index 122f0073faa..3f901b04f8e 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -18,6 +18,7 @@ package lib import ( + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -43,11 +44,11 @@ func initUpgradeCommand() *cobra.Command { } func runUpgradeCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors() + instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) err := lib.LibraryUpgradeAll(context.Background(), &rpc.LibraryUpgradeAllReq{ Instance: instance, - }, cli.OutputProgressBar(), cli.OutputTaskProgress()) + }, cli.OutputProgressBar(), cli.OutputTaskProgress(), http.Header{}) if err != nil { formatter.PrintError(err, "Error upgrading libraries") os.Exit(cli.ErrGeneric) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 23f264dab70..7ed63cac39c 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -19,6 +19,7 @@ package upload import ( "context" + "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -66,7 +67,7 @@ var flags struct { } func run(command *cobra.Command, args []string) { - instance := cli.CreateInstance() + instance := cli.CreateInstance(http.Header{}) var path *paths.Path if len(args) > 0 { diff --git a/commands/bundled_tools.go b/commands/bundled_tools.go index 88cd451d6e5..e907a52b262 100644 --- a/commands/bundled_tools.go +++ b/commands/bundled_tools.go @@ -19,6 +19,7 @@ package commands import ( "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" @@ -26,8 +27,8 @@ import ( ) // DownloadToolRelease downloads a ToolRelease -func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB DownloadProgressCB) error { - resp, err := pm.DownloadToolRelease(toolRelease) +func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB DownloadProgressCB, downloaderHeaders http.Header) error { + resp, err := pm.DownloadToolRelease(toolRelease, downloaderHeaders) if err != nil { return err } diff --git a/commands/core/download.go b/commands/core/download.go index ae07ffabdfc..170f0063933 100644 --- a/commands/core/download.go +++ b/commands/core/download.go @@ -21,6 +21,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" @@ -28,7 +29,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) -func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB) (*rpc.PlatformDownloadResp, error) { +func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) (*rpc.PlatformDownloadResp, error) { pm := commands.GetPackageManager(req) if pm == nil { return nil, errors.New("invalid instance") @@ -48,13 +49,13 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloa return nil, fmt.Errorf("find platform dependencies: %s", err) } - err = downloadPlatform(pm, platform, downloadCB) + err = downloadPlatform(pm, platform, downloadCB, downloaderHeaders) if err != nil { return nil, err } for _, tool := range tools { - err := downloadTool(pm, tool, downloadCB) + err := downloadTool(pm, tool, downloadCB, downloaderHeaders) if err != nil { return nil, fmt.Errorf("downloading tool %s: %s", tool, err) } @@ -63,20 +64,20 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloa return &rpc.PlatformDownloadResp{}, nil } -func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, downloadCB commands.DownloadProgressCB) error { +func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) error { // Download platform - resp, err := pm.DownloadPlatformRelease(platformRelease) + resp, err := pm.DownloadPlatformRelease(platformRelease, downloaderHeaders) if err != nil { return err } return commands.Download(resp, platformRelease.String(), downloadCB) } -func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB commands.DownloadProgressCB) error { +func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) error { // Check if tool has a flavor available for the current OS if tool.GetCompatibleFlavour() == nil { return fmt.Errorf("tool %s not available for the current OS", tool) } - return commands.DownloadToolRelease(pm, tool, downloadCB) + return commands.DownloadToolRelease(pm, tool, downloadCB, downloaderHeaders) } diff --git a/commands/core/install.go b/commands/core/install.go index 4963172a7cc..d418aafa3ec 100644 --- a/commands/core/install.go +++ b/commands/core/install.go @@ -21,6 +21,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" @@ -29,7 +30,7 @@ import ( ) func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq, - downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) (*rpc.PlatformInstallResp, error) { + downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) (*rpc.PlatformInstallResp, error) { pm := commands.GetPackageManager(req) if pm == nil { @@ -50,7 +51,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq, return nil, fmt.Errorf("finding platform dependencies: %s", err) } - err = installPlatform(pm, platform, tools, downloadCB, taskCB) + err = installPlatform(pm, platform, tools, downloadCB, taskCB, downloaderHeaders) if err != nil { return nil, err } @@ -65,7 +66,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq, func installPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, requiredTools []*cores.ToolRelease, - downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error { + downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { log := pm.Log.WithField("platform", platformRelease) // Prerequisite checks before install @@ -87,9 +88,9 @@ func installPlatform(pm *packagemanager.PackageManager, // Package download taskCB(&rpc.TaskProgress{Name: "Downloading packages"}) for _, tool := range toolsToInstall { - downloadTool(pm, tool, downloadCB) + downloadTool(pm, tool, downloadCB, downloaderHeaders) } - downloadPlatform(pm, platformRelease, downloadCB) + downloadPlatform(pm, platformRelease, downloadCB, downloaderHeaders) taskCB(&rpc.TaskProgress{Completed: true}) // Install tools first diff --git a/commands/core/upgrade.go b/commands/core/upgrade.go index 12e3715290c..6099ccfc59e 100644 --- a/commands/core/upgrade.go +++ b/commands/core/upgrade.go @@ -21,6 +21,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/commands" @@ -28,7 +29,7 @@ import ( ) func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq, - downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) (*rpc.PlatformUpgradeResp, error) { + downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) (*rpc.PlatformUpgradeResp, error) { pm := commands.GetPackageManager(req) if pm == nil { @@ -40,7 +41,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq, Package: req.PlatformPackage, PlatformArchitecture: req.Architecture, } - if err := upgradePlatform(pm, ref, downloadCB, taskCB); err != nil { + if err := upgradePlatform(pm, ref, downloadCB, taskCB, downloaderHeaders); err != nil { return nil, err } @@ -52,7 +53,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq, } func upgradePlatform(pm *packagemanager.PackageManager, platformRef *packagemanager.PlatformReference, - downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error { + downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { if platformRef.PlatformVersion != nil { return fmt.Errorf("upgrade doesn't accept parameters with version") } @@ -79,7 +80,7 @@ func upgradePlatform(pm *packagemanager.PackageManager, platformRef *packagemana if err != nil { return fmt.Errorf("platform %s is not installed", platformRef) } - err = installPlatform(pm, platform, tools, downloadCB, taskCB) + err = installPlatform(pm, platform, tools, downloadCB, taskCB, downloaderHeaders) if err != nil { return err } diff --git a/commands/instances.go b/commands/instances.go index 21915337b2c..c872b3c2489 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -21,6 +21,7 @@ import ( "context" "fmt" "io/ioutil" + "net/http" "net/url" "path" "time" @@ -82,12 +83,12 @@ func GetDiscoveries(req InstanceContainer) []*discovery.Discovery { return i.discoveries } -func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, downloadCB DownloadProgressCB, taskCB TaskProgressCB) (bool, error) { +func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, downloadCB DownloadProgressCB, taskCB TaskProgressCB, downloaderHeaders http.Header) (bool, error) { if tool.IsInstalled() { return false, nil } taskCB(&rpc.TaskProgress{Name: "Downloading missing tool " + tool.String()}) - if err := DownloadToolRelease(instance.pm, tool, downloadCB); err != nil { + if err := DownloadToolRelease(instance.pm, tool, downloadCB, downloaderHeaders); err != nil { return false, fmt.Errorf("downloading %s tool: %s", tool, err) } taskCB(&rpc.TaskProgress{Completed: true}) @@ -97,17 +98,17 @@ func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, down return true, nil } -func (instance *CoreInstance) checkForBuiltinTools(downloadCB DownloadProgressCB, taskCB TaskProgressCB) error { +func (instance *CoreInstance) checkForBuiltinTools(downloadCB DownloadProgressCB, taskCB TaskProgressCB, downloaderHeaders http.Header) error { // Check for ctags tool ctags, _ := getBuiltinCtagsTool(instance.pm) - ctagsInstalled, err := instance.installToolIfMissing(ctags, downloadCB, taskCB) + ctagsInstalled, err := instance.installToolIfMissing(ctags, downloadCB, taskCB, downloaderHeaders) if err != nil { return err } // Check for bultin serial-discovery tool serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(instance.pm) - serialDiscoveryInstalled, err := instance.installToolIfMissing(serialDiscoveryTool, downloadCB, taskCB) + serialDiscoveryInstalled, err := instance.installToolIfMissing(serialDiscoveryTool, downloadCB, taskCB, downloaderHeaders) if err != nil { return err } @@ -146,7 +147,7 @@ func (instance *CoreInstance) startDiscoveries() error { return nil } -func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, taskCB TaskProgressCB) (*rpc.InitResp, error) { +func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, taskCB TaskProgressCB, downloaderHeaders http.Header) (*rpc.InitResp, error) { inConfig := req.GetConfiguration() if inConfig == nil { return nil, fmt.Errorf("invalid request") @@ -182,7 +183,7 @@ func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, instancesCount++ instances[handle] = instance - if err := instance.checkForBuiltinTools(downloadCB, taskCB); err != nil { + if err := instance.checkForBuiltinTools(downloadCB, taskCB, downloaderHeaders); err != nil { fmt.Println(err) return nil, err } diff --git a/commands/lib/download.go b/commands/lib/download.go index 96310d6d142..0207161debf 100644 --- a/commands/lib/download.go +++ b/commands/lib/download.go @@ -20,6 +20,7 @@ package lib import ( "context" "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" @@ -28,7 +29,7 @@ import ( "github.com/sirupsen/logrus" ) -func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadCB commands.DownloadProgressCB) (*rpc.LibraryDownloadResp, error) { +func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) (*rpc.LibraryDownloadResp, error) { logrus.Info("Executing `arduino lib download`") lm := commands.GetLibraryManager(req) @@ -40,7 +41,7 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadC return nil, fmt.Errorf("looking for library: %s", err) } - if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}); err != nil { + if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, downloaderHeaders); err != nil { return nil, err } @@ -48,10 +49,10 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadC } func downloadLibrary(lm *librariesmanager.LibrariesManager, libRelease *librariesindex.Release, - downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error { + downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { taskCB(&rpc.TaskProgress{Name: "Downloading " + libRelease.String()}) - if d, err := libRelease.Resource.Download(lm.DownloadsDir); err != nil { + if d, err := libRelease.Resource.Download(lm.DownloadsDir, downloaderHeaders); err != nil { return err } else if err := commands.Download(d, libRelease.String(), downloadCB); err != nil { return err diff --git a/commands/lib/install.go b/commands/lib/install.go index c39d4fb2087..dac7d74f3eb 100644 --- a/commands/lib/install.go +++ b/commands/lib/install.go @@ -20,6 +20,7 @@ package lib import ( "context" "fmt" + "net/http" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" @@ -29,7 +30,7 @@ import ( ) func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq, - downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error { + downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { lm := commands.GetLibraryManager(req) @@ -38,7 +39,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq, return fmt.Errorf("looking for library: %s", err) } - if err := downloadLibrary(lm, libRelease, downloadCB, taskCB); err != nil { + if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloaderHeaders); err != nil { return fmt.Errorf("downloading library: %s", err) } diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index 1181f32a5fe..622d2cef9e8 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -20,19 +20,20 @@ package lib import ( "context" "fmt" + "net/http" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/rpc" ) -func LibraryUpgradeAll(ctx context.Context, req *rpc.LibraryUpgradeAllReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error { +func LibraryUpgradeAll(ctx context.Context, req *rpc.LibraryUpgradeAllReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { lm := commands.GetLibraryManager(req) // Obtain the list of upgradable libraries list := listLibraries(lm, true, true) for _, upgradeDesc := range list { - if err := downloadLibrary(lm, upgradeDesc.Available, downloadCB, taskCB); err != nil { + if err := downloadLibrary(lm, upgradeDesc.Available, downloadCB, taskCB, downloaderHeaders); err != nil { return err } } From f4b2e07c7db373a123f320fe6cf22335b0c38f7b Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 09:51:39 +0200 Subject: [PATCH 22/41] align downloader helper to use propagated http.Header from upper layers and modify test accordingly --- arduino/resources/helpers.go | 19 +++---------------- arduino/resources/helpers_test.go | 5 +++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/arduino/resources/helpers.go b/arduino/resources/helpers.go index a92e638c238..becdbf5b6a9 100644 --- a/arduino/resources/helpers.go +++ b/arduino/resources/helpers.go @@ -21,9 +21,7 @@ import ( "fmt" "net/http" "os" - "runtime" - "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "go.bug.st/downloader" ) @@ -48,7 +46,7 @@ func (r *DownloadResource) IsCached(downloadDir *paths.Path) (bool, error) { } // Download a DownloadResource. -func (r *DownloadResource) Download(downloadDir *paths.Path) (*downloader.Downloader, error) { +func (r *DownloadResource) Download(downloadDir *paths.Path, downloaderHeaders http.Header) (*downloader.Downloader, error) { cached, err := r.TestLocalArchiveIntegrity(downloadDir) if err != nil { return nil, fmt.Errorf("testing local archive integrity: %s", err) @@ -76,18 +74,7 @@ func (r *DownloadResource) Download(downloadDir *paths.Path) (*downloader.Downlo return nil, fmt.Errorf("getting archive file info: %s", err) } - downloadConfig := r.ConfigureDownloader() - return downloader.DownloadWithConfig(path.String(), r.URL, downloadConfig) -} - -// ConfigureDownloader adds additional config to the downloader helper -func (r *DownloadResource) ConfigureDownloader() downloader.Config { - userAgentHeaderValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), - version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) downloadConfig := downloader.Config{ - RequestHeaders: http.Header{ - "User-Agent": []string{userAgentHeaderValue}, - }, - } - return downloadConfig + RequestHeaders: downloaderHeaders} + return downloader.DownloadWithConfig(path.String(), r.URL, downloadConfig) } diff --git a/arduino/resources/helpers_test.go b/arduino/resources/helpers_test.go index 4600c564c90..2224e8bf3da 100644 --- a/arduino/resources/helpers_test.go +++ b/arduino/resources/helpers_test.go @@ -39,8 +39,9 @@ func (h *EchoHandler) ServeHTTP(writer http.ResponseWriter, request *http.Reques } func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { - goldUserAgentString := "User-Agent: " + fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), + userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) + goldUserAgentString := "User-Agent: " + userAgentValue tmp, err := paths.MkTempDir("", "") require.NoError(t, err) @@ -56,7 +57,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { URL: srv.URL, } - d, err := r.Download(tmp) + d, err := r.Download(tmp, http.Header{"User-Agent": []string{userAgentValue}}) require.NoError(t, err) err = d.Run() require.NoError(t, err) From ddd6bd10bee0ec171a75a8c3ac1ae51c490068f0 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 10:02:10 +0200 Subject: [PATCH 23/41] align daemon to use empty http.Header as struct field in ArduinoCoreServerImpl --- daemon/daemon.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index a2a65a04158..cd1538aeb31 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -25,6 +25,7 @@ import ( "io" "log" "net" + "net/http" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/commands" @@ -48,14 +49,18 @@ func runDaemonCommand(cmd *cobra.Command, args []string) { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - rpc.RegisterArduinoCoreServer(s, &ArduinoCoreServerImpl{}) + rpc.RegisterArduinoCoreServer(s, &ArduinoCoreServerImpl{ + downloaderHeaders: http.Header{}, + }) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) } fmt.Println("Done serving") } -type ArduinoCoreServerImpl struct{} +type ArduinoCoreServerImpl struct { + downloaderHeaders http.Header +} func (s *ArduinoCoreServerImpl) BoardDetails(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsResp, error) { return board.Details(ctx, req) @@ -112,6 +117,7 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In resp, err := commands.Init(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.InitResp{DownloadProgress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.InitResp{TaskProgress: p}) }, + s.downloaderHeaders, ) if err != nil { return err @@ -141,6 +147,7 @@ func (s *ArduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallReq, str stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.PlatformInstallResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.PlatformInstallResp{TaskProgress: p}) }, + s.downloaderHeaders, ) if err != nil { return err @@ -152,6 +159,7 @@ func (s *ArduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReq, s resp, err := core.PlatformDownload( stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.PlatformDownloadResp{Progress: p}) }, + s.downloaderHeaders, ) if err != nil { return err @@ -175,6 +183,7 @@ func (s *ArduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeReq, str stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.PlatformUpgradeResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.PlatformUpgradeResp{TaskProgress: p}) }, + s.downloaderHeaders, ) if err != nil { return err @@ -221,6 +230,7 @@ func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadReq, str resp, err := lib.LibraryDownload( stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryDownloadResp{Progress: p}) }, + s.downloaderHeaders, ) if err != nil { return err @@ -233,6 +243,7 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallReq, strea stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryInstallResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryInstallResp{TaskProgress: p}) }, + s.downloaderHeaders, ) if err != nil { return err @@ -254,6 +265,7 @@ func (s *ArduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllReq, err := lib.LibraryUpgradeAll(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryUpgradeAllResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryUpgradeAllResp{TaskProgress: p}) }, + s.downloaderHeaders, ) if err != nil { return err From 5f571ef68fcbfe0d919a28a7a4d2de16ca935e63 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 12:51:19 +0200 Subject: [PATCH 24/41] clean inside cobra commands for empty http.Header struct and inject headers build from VersionInfo struct in cli InitInstance func --- cli/board/attach.go | 3 +-- cli/board/details.go | 3 +-- cli/board/list.go | 3 +-- cli/board/listall.go | 3 +-- cli/cli.go | 21 ++++++++++++++------- cli/compile/compile.go | 3 +-- cli/core/download.go | 2 +- cli/core/install.go | 2 +- cli/core/list.go | 3 +-- cli/core/search.go | 3 +-- cli/core/uninstall.go | 3 +-- cli/core/update_index.go | 3 +-- cli/core/upgrade.go | 2 +- cli/lib/download.go | 2 +- cli/lib/install.go | 2 +- cli/lib/list.go | 3 +-- cli/lib/search.go | 3 +-- cli/lib/uninstall.go | 3 +-- cli/lib/update_index.go | 3 +-- cli/lib/upgrade.go | 2 +- cli/upload/upload.go | 3 +-- 21 files changed, 34 insertions(+), 41 deletions(-) diff --git a/cli/board/attach.go b/cli/board/attach.go index 4887829b2b1..a1fc5563a79 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -19,7 +19,6 @@ package board import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -50,7 +49,7 @@ var attachFlags struct { } func runAttachCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() var path string if len(args) > 0 { path = args[1] diff --git a/cli/board/details.go b/cli/board/details.go index a41c09d61cf..5239a9be999 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -44,7 +43,7 @@ func initDetailsCommand() *cobra.Command { } func runDetailsCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() res, err := board.Details(context.Background(), &rpc.BoardDetailsReq{ Instance: instance, diff --git a/cli/board/list.go b/cli/board/list.go index 74b96ed428a..280c0eb6db8 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "net/http" "os" "sort" "time" @@ -54,7 +53,7 @@ var listFlags struct { // runListCommand detects and lists the connected arduino boards func runListCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() if timeout, err := time.ParseDuration(listFlags.timeout); err != nil { formatter.PrintError(err, "Invalid timeout.") diff --git a/cli/board/listall.go b/cli/board/listall.go index 131c559c9bd..533d33eeda3 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -20,7 +20,6 @@ package board import ( "context" "fmt" - "net/http" "os" "sort" @@ -50,7 +49,7 @@ func initListAllCommand() *cobra.Command { // runListAllCommand list all installed boards func runListAllCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() list, err := board.ListAll(context.Background(), &rpc.BoardListAllReq{ Instance: instance, diff --git a/cli/cli.go b/cli/cli.go index ddef28cd47e..a08854273cf 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -20,9 +20,11 @@ package cli import ( "context" "errors" + "fmt" "net/http" "os" "path/filepath" + "runtime" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" @@ -85,9 +87,14 @@ func packageManagerInitReq() *rpc.InitReq { return &rpc.InitReq{Configuration: conf} } -func InitInstance(downloaderHeaders http.Header) *rpc.InitResp { +func InitInstance() *rpc.InitResp { logrus.Info("Initializing package manager") req := packageManagerInitReq() + + userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), + version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) + downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}} + resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress(), downloaderHeaders) if err != nil { formatter.PrintError(err, "Error initializing package manager") @@ -112,8 +119,8 @@ func InitInstance(downloaderHeaders http.Header) *rpc.InitResp { } // CreateInstance creates and return an instance of the Arduino Core engine -func CreateInstance(downloaderHeaders http.Header) *rpc.Instance { - resp := InitInstance(downloaderHeaders) +func CreateInstance() *rpc.Instance { + resp := InitInstance() if resp.GetPlatformsIndexErrors() != nil { for _, err := range resp.GetPlatformsIndexErrors() { formatter.PrintError(errors.New(err), "Error loading index") @@ -126,14 +133,14 @@ func CreateInstance(downloaderHeaders http.Header) *rpc.Instance { // CreateInstaceIgnorePlatformIndexErrors creates and return an instance of the // Arduino Core Engine, but won't stop on platforms index loading errors. -func CreateInstaceIgnorePlatformIndexErrors(downloaderHeaders http.Header) *rpc.Instance { - return InitInstance(downloaderHeaders).GetInstance() +func CreateInstaceIgnorePlatformIndexErrors() *rpc.Instance { + return InitInstance().GetInstance() } // InitPackageAndLibraryManager initializes the PackageManager and the // LibaryManager with the default configuration. (DEPRECATED) -func InitPackageAndLibraryManager(downloaderHeaders http.Header) (*packagemanager.PackageManager, *librariesmanager.LibrariesManager) { - resp := InitInstance(downloaderHeaders) +func InitPackageAndLibraryManager() (*packagemanager.PackageManager, *librariesmanager.LibrariesManager) { + resp := InitInstance() return commands.GetPackageManager(resp), commands.GetLibraryManager(resp) } diff --git a/cli/compile/compile.go b/cli/compile/compile.go index 55f9d98bf1c..d01274dce98 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -19,7 +19,6 @@ package compile import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -91,7 +90,7 @@ var flags struct { } func run(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() var path *paths.Path if len(args) > 0 { diff --git a/cli/core/download.go b/cli/core/download.go index 8983b68c532..f47b8dc3600 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -45,7 +45,7 @@ func initDownloadCommand() *cobra.Command { } func runDownloadCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() logrus.Info("Executing `arduino core download`") platformsRefs := parsePlatformReferenceArgs(args) diff --git a/cli/core/install.go b/cli/core/install.go index 9dcad5c0866..b709c7a5149 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -46,7 +46,7 @@ func initInstallCommand() *cobra.Command { } func runInstallCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() logrus.Info("Executing `arduino core install`") platformsRefs := parsePlatformReferenceArgs(args) diff --git a/cli/core/list.go b/cli/core/list.go index eb6a8e9fcd6..91efcd6c4cf 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -20,7 +20,6 @@ package core import ( "context" "fmt" - "net/http" "os" "sort" @@ -51,7 +50,7 @@ var listFlags struct { } func runListCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() logrus.Info("Executing `arduino core list`") resp, err := core.PlatformList(context.Background(), &rpc.PlatformListReq{ diff --git a/cli/core/search.go b/cli/core/search.go index c2edef92cba..0f752189357 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -20,7 +20,6 @@ package core import ( "context" "fmt" - "net/http" "os" "sort" "strings" @@ -47,7 +46,7 @@ func initSearchCommand() *cobra.Command { } func runSearchCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() logrus.Info("Executing `arduino core search`") arguments := strings.ToLower(strings.Join(args, " ")) diff --git a/cli/core/uninstall.go b/cli/core/uninstall.go index 65ef5c45b49..90e0472731d 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.go @@ -19,7 +19,6 @@ package core import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -43,7 +42,7 @@ func initUninstallCommand() *cobra.Command { } func runUninstallCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() logrus.Info("Executing `arduino core uninstall`") platformsRefs := parsePlatformReferenceArgs(args) diff --git a/cli/core/update_index.go b/cli/core/update_index.go index ebc2e03506b..13d832343f1 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -19,7 +19,6 @@ package core import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -43,7 +42,7 @@ func initUpdateIndexCommand() *cobra.Command { } func runUpdateIndexCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() logrus.Info("Executing `arduino core update-index`") _, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{ diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 2770a0a36ff..6db3453bc03 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -46,7 +46,7 @@ func initUpgradeCommand() *cobra.Command { } func runUpgradeCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() logrus.Info("Executing `arduino core upgrade`") platformsRefs := parsePlatformReferenceArgs(args) diff --git a/cli/lib/download.go b/cli/lib/download.go index c741ff207f3..a5114195e4e 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -45,7 +45,7 @@ func initDownloadCommand() *cobra.Command { } func runDownloadCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() pairs, err := librariesindex.ParseArgs(args) if err != nil { formatter.PrintError(err, "Arguments error") diff --git a/cli/lib/install.go b/cli/lib/install.go index 527a9c8dc03..475a151bf01 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -45,7 +45,7 @@ func initInstallCommand() *cobra.Command { } func runInstallCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() refs, err := librariesindex.ParseArgs(args) if err != nil { formatter.PrintError(err, "Arguments error") diff --git a/cli/lib/list.go b/cli/lib/list.go index 90995f11b32..5766ad19fa8 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -19,7 +19,6 @@ package lib import ( "fmt" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -52,7 +51,7 @@ var listFlags struct { } func runListCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() logrus.Info("Listing") res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{ diff --git a/cli/lib/search.go b/cli/lib/search.go index f9a5a525bf8..674f018eb01 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -20,7 +20,6 @@ package lib import ( "context" "fmt" - "net/http" "os" "sort" "strings" @@ -52,7 +51,7 @@ var searchFlags struct { } func runSearchCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() logrus.Info("Executing `arduino lib search`") searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchReq{ Instance: instance, diff --git a/cli/lib/uninstall.go b/cli/lib/uninstall.go index c08b8555cb9..6c38a93c9a6 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -19,7 +19,6 @@ package lib import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -46,7 +45,7 @@ func initUninstallCommand() *cobra.Command { func runUninstallCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino lib uninstall`") - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() libRefs, err := librariesindex.ParseArgs(args) if err != nil { formatter.PrintError(err, "Arguments error") diff --git a/cli/lib/update_index.go b/cli/lib/update_index.go index a8f4df25d85..6c7f22a3b62 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -19,7 +19,6 @@ package lib import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -37,7 +36,7 @@ func initUpdateIndexCommand() *cobra.Command { Example: " " + cli.VersionInfo.Application + " lib update-index", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{ Instance: instance, }, cli.OutputProgressBar()) diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index 3f901b04f8e..945d5302d70 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -44,7 +44,7 @@ func initUpgradeCommand() *cobra.Command { } func runUpgradeCommand(cmd *cobra.Command, args []string) { - instance := cli.CreateInstaceIgnorePlatformIndexErrors(http.Header{}) + instance := cli.CreateInstaceIgnorePlatformIndexErrors() err := lib.LibraryUpgradeAll(context.Background(), &rpc.LibraryUpgradeAllReq{ Instance: instance, diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 7ed63cac39c..23f264dab70 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -19,7 +19,6 @@ package upload import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -67,7 +66,7 @@ var flags struct { } func run(command *cobra.Command, args []string) { - instance := cli.CreateInstance(http.Header{}) + instance := cli.CreateInstance() var path *paths.Path if len(args) > 0 { From 4613a88cdcf614361e0173f3f9d72660fc44b02c Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 12:55:25 +0200 Subject: [PATCH 25/41] remove unused runDaemonCommand in daemon --- daemon/daemon.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index cd1538aeb31..39e53fcade9 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -23,8 +23,6 @@ import ( "context" "fmt" "io" - "log" - "net" "net/http" "github.com/arduino/arduino-cli/cli" @@ -35,29 +33,8 @@ import ( "github.com/arduino/arduino-cli/commands/lib" "github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/rpc" - "github.com/spf13/cobra" - "google.golang.org/grpc" ) -const ( - port = ":50051" -) - -func runDaemonCommand(cmd *cobra.Command, args []string) { - lis, err := net.Listen("tcp", port) - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - s := grpc.NewServer() - rpc.RegisterArduinoCoreServer(s, &ArduinoCoreServerImpl{ - downloaderHeaders: http.Header{}, - }) - if err := s.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } - fmt.Println("Done serving") -} - type ArduinoCoreServerImpl struct { downloaderHeaders http.Header } From 13a12ac6cf0c35006ec352e20941fd973969fcce Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 13:07:19 +0200 Subject: [PATCH 26/41] add user agent specific for daemon mode via DownloaderHeaders property for ArduinoCoreServerImpl --- cli/daemon/daemon.go | 12 +++++++++++- daemon/daemon.go | 16 ++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index f85b9b2bc10..dd51363255c 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -21,10 +21,13 @@ import ( "fmt" "log" "net" + "net/http" + "runtime" "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/daemon" "github.com/arduino/arduino-cli/rpc" + "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" "google.golang.org/grpc" ) @@ -53,7 +56,14 @@ func runDaemonCommand(cmd *cobra.Command, args []string) { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - rpc.RegisterArduinoCoreServer(s, &daemon.ArduinoCoreServerImpl{}) + + userAgentValue := fmt.Sprintf("%s daemon/%s (%s; %s; %s) Commit:%s/Build:%s ", version.GetApplication(), + version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) + headers := http.Header{"User-Agent": []string{userAgentValue}} + + coreServer := daemon.ArduinoCoreServerImpl{DownloaderHeaders: headers} + + rpc.RegisterArduinoCoreServer(s, &coreServer) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) } diff --git a/daemon/daemon.go b/daemon/daemon.go index 39e53fcade9..db9e8efdac0 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -36,7 +36,7 @@ import ( ) type ArduinoCoreServerImpl struct { - downloaderHeaders http.Header + DownloaderHeaders http.Header } func (s *ArduinoCoreServerImpl) BoardDetails(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsResp, error) { @@ -94,7 +94,7 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In resp, err := commands.Init(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.InitResp{DownloadProgress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.InitResp{TaskProgress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err @@ -124,7 +124,7 @@ func (s *ArduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallReq, str stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.PlatformInstallResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.PlatformInstallResp{TaskProgress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err @@ -136,7 +136,7 @@ func (s *ArduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReq, s resp, err := core.PlatformDownload( stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.PlatformDownloadResp{Progress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err @@ -160,7 +160,7 @@ func (s *ArduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeReq, str stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.PlatformUpgradeResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.PlatformUpgradeResp{TaskProgress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err @@ -207,7 +207,7 @@ func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadReq, str resp, err := lib.LibraryDownload( stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryDownloadResp{Progress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err @@ -220,7 +220,7 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallReq, strea stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryInstallResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryInstallResp{TaskProgress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err @@ -242,7 +242,7 @@ func (s *ArduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllReq, err := lib.LibraryUpgradeAll(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryUpgradeAllResp{Progress: p}) }, func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryUpgradeAllResp{TaskProgress: p}) }, - s.downloaderHeaders, + s.DownloaderHeaders, ) if err != nil { return err From a1d2a9204ce8c0a3ac5821572cd0402d412782c1 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 17:45:25 +0200 Subject: [PATCH 27/41] add testing information in README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 41703cce189..e282ed85425 100644 --- a/README.md +++ b/README.md @@ -333,3 +333,20 @@ Because: #### How can I find the core/FQBN for a board? See: https://github.com/arduino/arduino-cli#step-4-find-and-install-the-right-core + +# Testing + +Currently Unit and Integration test are available for launch in 2 ways: + +1. classic `go test ./...` to launch both unit and integration test + +2. via [task](https://taskfile.dev) that includes the following options: + +``` +* build: Build the project +* test: Run the full testsuite +* test-integration: Run integration tests only +* test-unit: Run unit tests only +``` + +For Example to launch unit tests only run: `task test-unit` \ No newline at end of file From 2035384e0271e736671e3b103f4c3bc7741d835a Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 17:46:19 +0200 Subject: [PATCH 28/41] removed getters and related usage for version package --- cli/cli.go | 4 ++-- cli/daemon/daemon.go | 6 ++---- cli/root/root.go | 5 ++--- version/version.go | 20 -------------------- 4 files changed, 6 insertions(+), 29 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index a08854273cf..198c2812d02 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -91,8 +91,8 @@ func InitInstance() *rpc.InitResp { logrus.Info("Initializing package manager") req := packageManagerInitReq() - userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), - version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) + userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", VersionInfo.Application, + VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit, VersionInfo.BuildDate) downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}} resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress(), downloaderHeaders) diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index dd51363255c..69452e8503f 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -27,7 +27,6 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/daemon" "github.com/arduino/arduino-cli/rpc" - "github.com/arduino/arduino-cli/version" "github.com/spf13/cobra" "google.golang.org/grpc" ) @@ -57,12 +56,11 @@ func runDaemonCommand(cmd *cobra.Command, args []string) { } s := grpc.NewServer() - userAgentValue := fmt.Sprintf("%s daemon/%s (%s; %s; %s) Commit:%s/Build:%s ", version.GetApplication(), - version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) + userAgentValue := fmt.Sprintf("%s/%s daemon (%s; %s; %s) Commit:%s/Build:%s", cli.VersionInfo.Application, + cli.VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), cli.VersionInfo.Commit, cli.VersionInfo.BuildDate) headers := http.Header{"User-Agent": []string{userAgentValue}} coreServer := daemon.ArduinoCoreServerImpl{DownloaderHeaders: headers} - rpc.RegisterArduinoCoreServer(s, &coreServer) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/cli/root/root.go b/cli/root/root.go index 93f2f0d5e50..f59f55629c0 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -35,7 +35,6 @@ import ( "github.com/arduino/arduino-cli/cli/version" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" - ver "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/mattn/go-colorable" "github.com/sirupsen/logrus" @@ -49,7 +48,7 @@ func Init() *cobra.Command { Use: "arduino-cli", Short: "Arduino CLI.", Long: "Arduino Command Line Interface (arduino-cli).", - Example: " " + ver.GetAppName() + " [flags...]", + Example: " " + cli.VersionInfo.Application + " [flags...]", PersistentPreRun: preRun, } command.PersistentFlags().BoolVar(&cli.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).") @@ -92,7 +91,7 @@ func preRun(cmd *cobra.Command, args []string) { } initConfigs() - logrus.Info(ver.GetAppName() + "-" + ver.GetVersion()) + logrus.Info(cli.VersionInfo.Application + "-" + cli.VersionInfo.VersionString) logrus.Info("Starting root command preparation (`arduino`)") switch outputFormat { case "text": diff --git a/version/version.go b/version/version.go index 28cf174a849..ac59179407c 100644 --- a/version/version.go +++ b/version/version.go @@ -29,26 +29,6 @@ var ( buildDate = time.Time{} ) -func GetAppName() string { - return "" -} - -func GetApplication() string { - return "" -} - -func GetVersion() string { - return defaultVersionString -} - -func GetCommit() string { - return commit -} - -func GetBuildDate() string { - return "" -} - type Info struct { Application string `json:"Application"` VersionString string `json:"VersionString"` From b2bb96ad97033a83e47b3527be2e536f5613d79d Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Fri, 7 Jun 2019 17:46:38 +0200 Subject: [PATCH 29/41] update dependencies --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index 40f5428b626..7a4654cb978 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,7 @@ require ( golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/net v0.0.0-20190311183353-d8887717615a golang.org/x/text v0.3.2 + google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect google.golang.org/grpc v1.21.1 gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect From a363e861d1aeea115e870357ec8ce1f537181493 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Mon, 10 Jun 2019 10:26:07 +0200 Subject: [PATCH 30/41] finalize helpers_test User-Agent header value --- arduino/resources/helpers_test.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arduino/resources/helpers_test.go b/arduino/resources/helpers_test.go index 2224e8bf3da..702634f3df5 100644 --- a/arduino/resources/helpers_test.go +++ b/arduino/resources/helpers_test.go @@ -22,11 +22,9 @@ import ( "io/ioutil" "net/http" "net/http/httptest" - "runtime" "strings" "testing" - "github.com/arduino/arduino-cli/version" "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" ) @@ -39,9 +37,8 @@ func (h *EchoHandler) ServeHTTP(writer http.ResponseWriter, request *http.Reques } func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { - userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", version.GetApplication(), - version.GetVersion(), runtime.GOARCH, runtime.GOOS, runtime.Version(), version.GetCommit(), version.GetBuildDate()) - goldUserAgentString := "User-Agent: " + userAgentValue + goldUserAgentValue := fmt.Sprintf("arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111") + goldUserAgentString := "User-Agent: " + goldUserAgentValue tmp, err := paths.MkTempDir("", "") require.NoError(t, err) @@ -57,7 +54,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { URL: srv.URL, } - d, err := r.Download(tmp, http.Header{"User-Agent": []string{userAgentValue}}) + d, err := r.Download(tmp, http.Header{"User-Agent": []string{goldUserAgentValue}}) require.NoError(t, err) err = d.Run() require.NoError(t, err) @@ -67,7 +64,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { // expect something like: // GET /echo HTTP/1.1 // Host: 127.0.0.1:64999 - // User-Agent: arduino-cli/0.3.6-alpha.preview (amd64; linux; go1.10) Commit:missing/Build:missing + // User-Agent: arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111 // Accept-Encoding: gzip b, err := ioutil.ReadFile(tmp.String() + "/cache/echo.txt") // just pass the file name From c51d2a1d64e32262d3c9e5a801fe55e738a25109 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Mon, 10 Jun 2019 17:03:33 +0200 Subject: [PATCH 31/41] add integration test for version info injection via vars --- Taskfile.yml | 9 +++++++- version/version_test.go | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 version/version_test.go diff --git a/Taskfile.yml b/Taskfile.yml index 9cf78a338ba..f365afd3f52 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,5 +1,12 @@ version: '2' +vars: + TEST_VERSIONSTRING: "0.0.0-test.preview" + TEST_COMMIT: "deadbeef" + TEST_LDFLAGS_VALUE: > + '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}} + -X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}' + tasks: build: desc: Build the project @@ -20,4 +27,4 @@ tasks: test-integration: desc: Run integration tests only cmds: - - go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} + - go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} -ldflags {{.TEST_LDFLAGS_VALUE}} diff --git a/version/version_test.go b/version/version_test.go new file mode 100644 index 00000000000..a7e194f14e4 --- /dev/null +++ b/version/version_test.go @@ -0,0 +1,47 @@ +/* + * 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 defaultVersionString 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 version + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +// TestIntegrationBuildInjectedInfo is an integration test that aims to test the Info strings passed to the binary at build time +// in order to have this test green launch your testing using the provided task (see /Taskfile.yml) or use: +// go test -run Integration -v ./... -ldflags '-X github.com/arduino/arduino-cli/version.versionString=0.0.0-test.preview -X github.com/arduino/arduino-cli/version.commit=deadbeef' +func TestIntegrationBuildInjectedInfo(t *testing.T) { + if testing.Short() { + t.Skip("skip integration test") + } + goldenAppName := "arduino-cli" + goldenInfo := Info{ + Application: goldenAppName, + VersionString: "0.0.0-test.preview", + Commit: "deadbeef", + BuildDate: time.Time{}, + } + info := NewInfo(goldenAppName) + require.Equal(t, goldenInfo.Application, info.Application) + require.Equal(t, goldenInfo.VersionString, info.VersionString) + require.Equal(t, goldenInfo.Commit, info.Commit) + require.IsType(t, time.Time{}, info.BuildDate) + require.False(t, info.BuildDate.IsZero()) +} From 3d55de06463904033250ea6644619570536dbe85 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Mon, 10 Jun 2019 18:22:35 +0200 Subject: [PATCH 32/41] tidy go mod and reorganize imports and tidy long lines --- cli/cli.go | 2 +- cli/version/version.go | 1 - commands/bundled_tools.go | 3 ++- commands/core/download.go | 9 ++++++--- commands/instances.go | 6 ++++-- commands/lib/download.go | 3 ++- commands/lib/upgrade.go | 3 ++- go.mod | 3 +-- go.sum | 7 ------- version/version.go | 1 + version/version_test.go | 4 +++- 11 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 198c2812d02..c522750b13c 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -55,7 +55,7 @@ const ( // appName is the command line name of the Arduino CLI executable on the user system (users may change it) var appName = filepath.Base(os.Args[0]) -// func NewInfo(application string, versionString string, commit string) *Info { +// VersionInfo contains all info injected during build var VersionInfo = version.NewInfo(appName) // ErrLogrus represents the logrus instance, which has the role to diff --git a/cli/version/version.go b/cli/version/version.go index a9894d48802..2ffacd5c6a4 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -19,7 +19,6 @@ package version import ( "fmt" - "github.com/arduino/arduino-cli/global" "github.com/arduino/arduino-cli/cli" "github.com/spf13/cobra" diff --git a/commands/bundled_tools.go b/commands/bundled_tools.go index e907a52b262..41b430858f1 100644 --- a/commands/bundled_tools.go +++ b/commands/bundled_tools.go @@ -27,7 +27,8 @@ import ( ) // DownloadToolRelease downloads a ToolRelease -func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB DownloadProgressCB, downloaderHeaders http.Header) error { +func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, + downloadCB DownloadProgressCB, downloaderHeaders http.Header) error { resp, err := pm.DownloadToolRelease(toolRelease, downloaderHeaders) if err != nil { return err diff --git a/commands/core/download.go b/commands/core/download.go index 170f0063933..86e389b20f8 100644 --- a/commands/core/download.go +++ b/commands/core/download.go @@ -29,7 +29,8 @@ import ( "github.com/arduino/arduino-cli/rpc" ) -func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) (*rpc.PlatformDownloadResp, error) { +func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB, + downloaderHeaders http.Header) (*rpc.PlatformDownloadResp, error) { pm := commands.GetPackageManager(req) if pm == nil { return nil, errors.New("invalid instance") @@ -64,7 +65,8 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloa return &rpc.PlatformDownloadResp{}, nil } -func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) error { +func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, + downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) error { // Download platform resp, err := pm.DownloadPlatformRelease(platformRelease, downloaderHeaders) if err != nil { @@ -73,7 +75,8 @@ func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores. return commands.Download(resp, platformRelease.String(), downloadCB) } -func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) error { +func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB commands.DownloadProgressCB, + downloaderHeaders http.Header) error { // Check if tool has a flavor available for the current OS if tool.GetCompatibleFlavour() == nil { return fmt.Errorf("tool %s not available for the current OS", tool) diff --git a/commands/instances.go b/commands/instances.go index c872b3c2489..e26852e1ac3 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -83,7 +83,8 @@ func GetDiscoveries(req InstanceContainer) []*discovery.Discovery { return i.discoveries } -func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, downloadCB DownloadProgressCB, taskCB TaskProgressCB, downloaderHeaders http.Header) (bool, error) { +func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, downloadCB DownloadProgressCB, + taskCB TaskProgressCB, downloaderHeaders http.Header) (bool, error) { if tool.IsInstalled() { return false, nil } @@ -98,7 +99,8 @@ func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, down return true, nil } -func (instance *CoreInstance) checkForBuiltinTools(downloadCB DownloadProgressCB, taskCB TaskProgressCB, downloaderHeaders http.Header) error { +func (instance *CoreInstance) checkForBuiltinTools(downloadCB DownloadProgressCB, taskCB TaskProgressCB, + downloaderHeaders http.Header) error { // Check for ctags tool ctags, _ := getBuiltinCtagsTool(instance.pm) ctagsInstalled, err := instance.installToolIfMissing(ctags, downloadCB, taskCB, downloaderHeaders) diff --git a/commands/lib/download.go b/commands/lib/download.go index 0207161debf..a46bddd4c85 100644 --- a/commands/lib/download.go +++ b/commands/lib/download.go @@ -29,7 +29,8 @@ import ( "github.com/sirupsen/logrus" ) -func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) (*rpc.LibraryDownloadResp, error) { +func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadCB commands.DownloadProgressCB, + downloaderHeaders http.Header) (*rpc.LibraryDownloadResp, error) { logrus.Info("Executing `arduino lib download`") lm := commands.GetLibraryManager(req) diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index 622d2cef9e8..ae0e4be1cd5 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -26,7 +26,8 @@ import ( "github.com/arduino/arduino-cli/rpc" ) -func LibraryUpgradeAll(ctx context.Context, req *rpc.LibraryUpgradeAllReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { +func LibraryUpgradeAll(ctx context.Context, req *rpc.LibraryUpgradeAllReq, downloadCB commands.DownloadProgressCB, + taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { lm := commands.GetLibraryManager(req) // Obtain the list of upgradable libraries diff --git a/go.mod b/go.mod index 7a4654cb978..5a519c16e1e 100644 --- a/go.mod +++ b/go.mod @@ -43,8 +43,7 @@ require ( go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/net v0.0.0-20190311183353-d8887717615a - golang.org/x/text v0.3.2 - google.golang.org/appengine v1.4.0 // indirect + golang.org/x/text v0.3.0 google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect google.golang.org/grpc v1.21.1 gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect diff --git a/go.sum b/go.sum index 83c02cc4c9e..ba5493edcea 100644 --- a/go.sum +++ b/go.sum @@ -131,7 +131,6 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -139,20 +138,14 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/version/version.go b/version/version.go index ac59179407c..c59cc26c398 100644 --- a/version/version.go +++ b/version/version.go @@ -49,6 +49,7 @@ func (i *Info) String() string { return fmt.Sprintf("%s Version: %s Commit: %s BuildDate: %s", i.Application, i.VersionString, i.Commit, i.BuildDate) } +//nolint:gochecknoinits func init() { if versionString == "" { versionString = defaultVersionString diff --git a/version/version_test.go b/version/version_test.go index a7e194f14e4..118174fb214 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -26,7 +26,9 @@ import ( // TestIntegrationBuildInjectedInfo is an integration test that aims to test the Info strings passed to the binary at build time // in order to have this test green launch your testing using the provided task (see /Taskfile.yml) or use: -// go test -run Integration -v ./... -ldflags '-X github.com/arduino/arduino-cli/version.versionString=0.0.0-test.preview -X github.com/arduino/arduino-cli/version.commit=deadbeef' +// go test -run Integration -v ./... -ldflags ' +// -X github.com/arduino/arduino-cli/version.versionString=0.0.0-test.preview +// -X github.com/arduino/arduino-cli/version.commit=deadbeef' func TestIntegrationBuildInjectedInfo(t *testing.T) { if testing.Short() { t.Skip("skip integration test") From 87ba21096d11f863b066617b73f15a9d868c9a01 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 09:40:15 +0200 Subject: [PATCH 33/41] inject ldflags variables in build task in Taskfile.yml --- Taskfile.yml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index f365afd3f52..506073d3ef4 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,17 +1,10 @@ version: '2' -vars: - TEST_VERSIONSTRING: "0.0.0-test.preview" - TEST_COMMIT: "deadbeef" - TEST_LDFLAGS_VALUE: > - '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}} - -X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}' - tasks: build: desc: Build the project cmds: - - go build -v -i + - go build -v -i -ldflags {{.LDFLAGS_VALUE}} test: desc: Run the full testsuite @@ -28,3 +21,20 @@ tasks: desc: Run integration tests only cmds: - go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} -ldflags {{.TEST_LDFLAGS_VALUE}} + + +vars: + # build flags + VERSIONSTRING: "0.3.6-alpha.preview" + COMMIT: + sh: echo ${TRAVIS_COMMIT:-`git log -n 1 --format=%h`} + LDFLAGS_VALUE: > + '-X github.com/arduino/arduino-cli/version.versionString={{.VERSIONSTRING}} + -X github.com/arduino/arduino-cli/version.commit={{.COMMIT}}' + + # test flags + TEST_VERSIONSTRING: "0.0.0-test.preview" + TEST_COMMIT: "deadbeef" + TEST_LDFLAGS_VALUE: > + '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}} + -X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}' \ No newline at end of file From 0ea3f427e202c27e0ed4e1a1d42f4a9e8b18ee16 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 10:46:21 +0200 Subject: [PATCH 34/41] replace commands in /travis.yml with tasks properly merging flags --- .travis.yml | 9 ++++++--- Taskfile.yml | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 766eaac31cb..cc1df2a8260 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ env: # Make sure golangci-lint is vendored. before_install: - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.16.0 + - go install github.com/go-task/task/cmd/task + install: true @@ -20,9 +22,10 @@ script: # Run linter - golangci-lint run # Build and test - - go build - - go test -timeout 20m -v -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./... + - task build + - task test after_success: - - bash <(curl -s https://codecov.io/bash) + - bash <(curl -s https://codecov.io/bash) -cF unittests,integration + diff --git a/Taskfile.yml b/Taskfile.yml index 506073d3ef4..e72d85d6fcc 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,7 +4,7 @@ tasks: build: desc: Build the project cmds: - - go build -v -i -ldflags {{.LDFLAGS_VALUE}} + - go build -v -i {{.LDFLAGS}} test: desc: Run the full testsuite @@ -15,26 +15,26 @@ tasks: test-unit: desc: Run unit tests only cmds: - - go test -short {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} + - go test -short {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default "./..." .TARGETS }} test-integration: desc: Run integration tests only cmds: - - go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} -ldflags {{.TEST_LDFLAGS_VALUE}} - + - go test -run Integration {{ default "-v" .GOFLAGS }} -coverprofile=coverage_integ.txt {{ default "./..." .TARGETS }} {{.TEST_LDFLAGS}} vars: - # build flags + # build vars VERSIONSTRING: "0.3.6-alpha.preview" COMMIT: sh: echo ${TRAVIS_COMMIT:-`git log -n 1 --format=%h`} - LDFLAGS_VALUE: > - '-X github.com/arduino/arduino-cli/version.versionString={{.VERSIONSTRING}} + LDFLAGS: > + -ldflags '-X github.com/arduino/arduino-cli/version.versionString={{.VERSIONSTRING}} -X github.com/arduino/arduino-cli/version.commit={{.COMMIT}}' - # test flags + # test vars + GOFLAGS: "-timeout 5m -v -coverpkg=./... -covermode=atomic" TEST_VERSIONSTRING: "0.0.0-test.preview" TEST_COMMIT: "deadbeef" - TEST_LDFLAGS_VALUE: > - '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}} + TEST_LDFLAGS: > + -ldflags '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}} -X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}' \ No newline at end of file From 685e1aa1fb8d77f89fed74fb35eb669ddd0e41d0 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 11:04:38 +0200 Subject: [PATCH 35/41] fix install command for go-task to solve "undefined: interp.EnvFromList" error --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc1df2a8260..3618eb204e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,7 @@ env: # Make sure golangci-lint is vendored. before_install: - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.16.0 - - go install github.com/go-task/task/cmd/task - + - curl -sL https://taskfile.dev/install.sh | sh install: true From 5fc270c80a79655794fc3f8964dd2afebd9d8c6c Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 12:42:31 +0200 Subject: [PATCH 36/41] add coverage files to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0ff7b75a308..199c1fe75e4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /cmd/formatter/debug.test /arduino-cli.yaml /wiki -.idea \ No newline at end of file +.idea +coverage_*.txt \ No newline at end of file From e2586ca339fac3534338de971737d3475be51e3e Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 12:44:10 +0200 Subject: [PATCH 37/41] tidy dependencies in go.mod --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index 5a519c16e1e..963669b19cf 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,7 @@ require ( golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/net v0.0.0-20190311183353-d8887717615a golang.org/x/text v0.3.0 + google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect google.golang.org/grpc v1.21.1 gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect From 47ff9c05d413583e220487f2a8f11093378bf733 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 12:53:45 +0200 Subject: [PATCH 38/41] update task executable path in tasks due to install path generated by go-task install script --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3618eb204e1..e0792890dbf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,8 +21,8 @@ script: # Run linter - golangci-lint run # Build and test - - task build - - task test + - ./bin/task build + - ./bin/task test after_success: - bash <(curl -s https://codecov.io/bash) -cF unittests,integration From b724edf0d31e2dc5a5265524cd0362fc465b4518 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 17:18:20 +0200 Subject: [PATCH 39/41] implement exported variable cli.HTTPClientHeader in order to have it available in all cli subpackages and not onli in cli --- cli/cli.go | 15 ++++++++++----- cli/core/download.go | 9 ++++----- cli/core/install.go | 7 ++++--- cli/core/upgrade.go | 3 +-- cli/lib/download.go | 7 ++++--- cli/lib/install.go | 7 ++++--- cli/lib/upgrade.go | 3 +-- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index c522750b13c..54e028e0f1b 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -58,6 +58,8 @@ var appName = filepath.Base(os.Args[0]) // VersionInfo contains all info injected during build var VersionInfo = version.NewInfo(appName) +var HTTPClientHeader = getHTTPClientHeader() + // ErrLogrus represents the logrus instance, which has the role to // log all non info messages. var ErrLogrus = logrus.New() @@ -87,15 +89,18 @@ func packageManagerInitReq() *rpc.InitReq { return &rpc.InitReq{Configuration: conf} } -func InitInstance() *rpc.InitResp { - logrus.Info("Initializing package manager") - req := packageManagerInitReq() - +func getHTTPClientHeader() http.Header { userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", VersionInfo.Application, VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit, VersionInfo.BuildDate) downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}} + return downloaderHeaders +} + +func InitInstance() *rpc.InitResp { + logrus.Info("Initializing package manager") + req := packageManagerInitReq() - resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress(), downloaderHeaders) + resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress(), HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error initializing package manager") os.Exit(ErrGeneric) diff --git a/cli/core/download.go b/cli/core/download.go index f47b8dc3600..0808baf6af0 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -19,7 +19,6 @@ package core import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -50,14 +49,14 @@ func runDownloadCommand(cmd *cobra.Command, args []string) { platformsRefs := parsePlatformReferenceArgs(args) for i, platformRef := range platformsRefs { - _, err := core.PlatformDownload(context.Background(), &rpc.PlatformDownloadReq{ + platformDownloadreq := &rpc.PlatformDownloadReq{ Instance: instance, PlatformPackage: platformRef.Package, Architecture: platformRef.Architecture, Version: platformRef.Version, - }, cli.OutputProgressBar(), - http.Header{}, - ) + } + _, err := core.PlatformDownload(context.Background(), platformDownloadreq, cli.OutputProgressBar(), + cli.HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error downloading "+args[i]) os.Exit(cli.ErrNetwork) diff --git a/cli/core/install.go b/cli/core/install.go index b709c7a5149..0a74d5afc72 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -19,7 +19,6 @@ package core import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -52,12 +51,14 @@ func runInstallCommand(cmd *cobra.Command, args []string) { platformsRefs := parsePlatformReferenceArgs(args) for _, platformRef := range platformsRefs { - _, err := core.PlatformInstall(context.Background(), &rpc.PlatformInstallReq{ + plattformInstallReq := &rpc.PlatformInstallReq{ Instance: instance, PlatformPackage: platformRef.Package, Architecture: platformRef.Architecture, Version: platformRef.Version, - }, cli.OutputProgressBar(), cli.OutputTaskProgress(), http.Header{}) + } + _, err := core.PlatformInstall(context.Background(), plattformInstallReq, cli.OutputProgressBar(), + cli.OutputTaskProgress(), cli.HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error during install") os.Exit(cli.ErrGeneric) diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 6db3453bc03..cbf74215ffa 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -19,7 +19,6 @@ package core import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -62,7 +61,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) { PlatformPackage: platformRef.Package, Architecture: platformRef.Architecture, }, cli.OutputProgressBar(), cli.OutputTaskProgress(), - http.Header{}) + cli.HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error during upgrade") os.Exit(cli.ErrGeneric) diff --git a/cli/lib/download.go b/cli/lib/download.go index a5114195e4e..3778f32cb94 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -19,7 +19,6 @@ package lib import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -52,11 +51,13 @@ func runDownloadCommand(cmd *cobra.Command, args []string) { os.Exit(cli.ErrBadArgument) } for _, library := range pairs { - _, err := lib.LibraryDownload(context.Background(), &rpc.LibraryDownloadReq{ + libraryDownloadReq := &rpc.LibraryDownloadReq{ Instance: instance, Name: library.Name, Version: library.Version.String(), - }, cli.OutputProgressBar(), http.Header{}) + } + _, err := lib.LibraryDownload(context.Background(), libraryDownloadReq, cli.OutputProgressBar(), + cli.HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error downloading "+library.String()) os.Exit(cli.ErrNetwork) diff --git a/cli/lib/install.go b/cli/lib/install.go index 475a151bf01..e534e6e2164 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -19,7 +19,6 @@ package lib import ( "context" - "net/http" "os" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -52,11 +51,13 @@ func runInstallCommand(cmd *cobra.Command, args []string) { os.Exit(cli.ErrBadArgument) } for _, library := range refs { - err := lib.LibraryInstall(context.Background(), &rpc.LibraryInstallReq{ + libraryInstallReq := &rpc.LibraryInstallReq{ Instance: instance, Name: library.Name, Version: library.Version.String(), - }, cli.OutputProgressBar(), cli.OutputTaskProgress(), http.Header{}) + } + err := lib.LibraryInstall(context.Background(), libraryInstallReq, cli.OutputProgressBar(), + cli.OutputTaskProgress(), cli.HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error installing "+library.String()) os.Exit(cli.ErrGeneric) diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index 945d5302d70..95c59310b41 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -18,7 +18,6 @@ package lib import ( - "net/http" "os" "github.com/arduino/arduino-cli/cli" @@ -48,7 +47,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) { err := lib.LibraryUpgradeAll(context.Background(), &rpc.LibraryUpgradeAllReq{ Instance: instance, - }, cli.OutputProgressBar(), cli.OutputTaskProgress(), http.Header{}) + }, cli.OutputProgressBar(), cli.OutputTaskProgress(), cli.HTTPClientHeader) if err != nil { formatter.PrintError(err, "Error upgrading libraries") os.Exit(cli.ErrGeneric) From b6bb5af299e0f6af8511f24dadefbb7a2fc86e38 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 17:20:39 +0200 Subject: [PATCH 40/41] fix comment replacing "version config" with "global config" --- cli/root/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/root/root.go b/cli/root/root.go index f59f55629c0..894011b57db 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -126,7 +126,7 @@ func initConfigs() { cli.Config = conf } - // Read configuration from version config file + // Read configuration from global config file logrus.Info("Checking for config file in: " + cli.Config.ConfigFile.String()) if cli.Config.ConfigFile.Exist() { readConfigFrom(cli.Config.ConfigFile) From c296fa0e9b4e0a00ad56c335106f21f2feb88f64 Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 11 Jun 2019 17:40:35 +0200 Subject: [PATCH 41/41] leverage cli.VersionInfo to present a better terminal and json data for version info --- cli/version/version.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cli/version/version.go b/cli/version/version.go index 2ffacd5c6a4..824460d38cc 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -38,16 +38,20 @@ func InitCommand() *cobra.Command { } type versionOutput struct { - Command string `json:"command"` - Version string `json:"version"` + Command string `json:"command"` + Version string `json:"version"` + Commit string `json:"commit"` + BuildDate string `json:"build_date"` } func run(cmd *cobra.Command, args []string) { res := &versionOutput{ - Command: cmd.Parent().Name(), - Version: cli.VersionInfo.VersionString, + Command: cmd.Parent().Name(), + Version: cli.VersionInfo.VersionString, + Commit: cli.VersionInfo.Commit, + BuildDate: cli.VersionInfo.BuildDate.String(), } if cli.OutputJSONOrElse(res) { - fmt.Printf("%s version %s\n", res.Command, res.Version) + fmt.Printf("%s\n", cli.VersionInfo) } }