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 diff --git a/cli/board/attach.go b/cli/board/attach.go index df59516027e..aed25a8fcc0 100644 --- a/cli/board/attach.go +++ b/cli/board/attach.go @@ -24,6 +24,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/rpc" "github.com/spf13/cobra" ) @@ -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..2c9d002ea70 100644 --- a/cli/board/details.go +++ b/cli/board/details.go @@ -25,6 +25,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" @@ -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..4cb54a9150f 100644 --- a/cli/board/list.go +++ b/cli/board/list.go @@ -27,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" @@ -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..008057ecadf 100644 --- a/cli/board/listall.go +++ b/cli/board/listall.go @@ -26,6 +26,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" @@ -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..328344030b6 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -21,15 +21,15 @@ 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" ) @@ -61,9 +61,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 +113,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..db98631b59f 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -24,6 +24,7 @@ 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/go-paths-helper" "github.com/spf13/cobra" @@ -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..f277b7f4f00 100644 --- a/cli/config/dump.go +++ b/cli/config/dump.go @@ -23,6 +23,7 @@ import ( "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" ) @@ -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..579ed48a8f9 100644 --- a/cli/config/init.go +++ b/cli/config/init.go @@ -22,6 +22,7 @@ import ( "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" ) @@ -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..6a8fc66b061 100644 --- a/cli/core/download.go +++ b/cli/core/download.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,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..67492498153 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -26,6 +26,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" @@ -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..01b1d77ea7d 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -27,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" @@ -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..9ef897caf99 100644 --- a/cli/core/uninstall.go +++ b/cli/core/uninstall.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/output" "github.com/arduino/arduino-cli/rpc" "github.com/sirupsen/logrus" @@ -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..cee08e9c64e 100644 --- a/cli/core/update_index.go +++ b/cli/core/update_index.go @@ -24,6 +24,7 @@ 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/sirupsen/logrus" "github.com/spf13/cobra" @@ -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..a8ff7a15caa 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.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" @@ -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..2d757cb342a 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -22,8 +22,8 @@ import ( "log" "net" - "github.com/arduino/arduino-cli/cli" "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" @@ -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..83eee15e42d 100644 --- a/cli/generatedocs/generatedocs.go +++ b/cli/generatedocs/generatedocs.go @@ -22,6 +22,7 @@ import ( "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" @@ -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..07af7e6191e 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -21,11 +21,11 @@ import ( "context" "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" ) @@ -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: "" + - " " + 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..0f4afcd9954 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -21,12 +21,12 @@ import ( "context" "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" ) @@ -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: "" + - " " + 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..08b730632da 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -24,6 +24,7 @@ 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/gosuri/uitable" "github.com/sirupsen/logrus" @@ -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..4c731b7c5a6 100644 --- a/cli/lib/search.go +++ b/cli/lib/search.go @@ -22,12 +22,12 @@ import ( "fmt" "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" @@ -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: " " + 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..1fb7f5f5c8b 100644 --- a/cli/lib/uninstall.go +++ b/cli/lib/uninstall.go @@ -25,6 +25,7 @@ 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/sirupsen/logrus" "github.com/spf13/cobra" @@ -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..032a96d2c26 100644 --- a/cli/lib/update_index.go +++ b/cli/lib/update_index.go @@ -24,6 +24,7 @@ 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/spf13/cobra" ) @@ -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..cd230102928 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -23,6 +23,7 @@ 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/sirupsen/logrus" "github.com/spf13/cobra" @@ -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/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/cli/root/root.go b/cli/root/root.go index ee6cabcd2bb..9e470165702 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -35,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" @@ -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() + "-" + global.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 685aafbfbcf..5469d23b028 100644 --- a/cli/sketch/new.go +++ b/cli/sketch/new.go @@ -22,6 +22,7 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/common/formatter" + "github.com/arduino/arduino-cli/global" "github.com/spf13/cobra" ) @@ -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..e7d4527c1ec 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -24,6 +24,7 @@ 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/go-paths-helper" "github.com/spf13/cobra" @@ -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..f36d8ba8490 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/arduino/arduino-cli/cli" + "github.com/arduino/arduino-cli/global" "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, } @@ -45,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/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/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 { diff --git a/global/global.go b/global/global.go new file mode 100644 index 00000000000..9a964b2c76e --- /dev/null +++ b/global/global.go @@ -0,0 +1,72 @@ +/* + * 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 ( + "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 = "0.3.6-alpha.preview" + 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"` +} 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=