From 47a7b59f37bc273d165737e47212cf5b03fc137f Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 5 Jun 2019 12:53:42 +0200 Subject: [PATCH 1/5] move config package under cli --- {commands => cli}/config/config.go | 0 {commands => cli}/config/dump.go | 0 {commands => cli}/config/init.go | 0 cli/root/root.go | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename {commands => cli}/config/config.go (100%) rename {commands => cli}/config/dump.go (100%) rename {commands => cli}/config/init.go (100%) diff --git a/commands/config/config.go b/cli/config/config.go similarity index 100% rename from commands/config/config.go rename to cli/config/config.go diff --git a/commands/config/dump.go b/cli/config/dump.go similarity index 100% rename from commands/config/dump.go rename to cli/config/dump.go diff --git a/commands/config/init.go b/cli/config/init.go similarity index 100% rename from commands/config/init.go rename to cli/config/init.go diff --git a/cli/root/root.go b/cli/root/root.go index 9260900c78d..90905c64d7e 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -25,13 +25,13 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/cli/board" "github.com/arduino/arduino-cli/cli/compile" + "github.com/arduino/arduino-cli/cli/config" "github.com/arduino/arduino-cli/cli/core" "github.com/arduino/arduino-cli/cli/daemon" "github.com/arduino/arduino-cli/cli/lib" "github.com/arduino/arduino-cli/cli/sketch" "github.com/arduino/arduino-cli/cli/upload" "github.com/arduino/arduino-cli/cli/version" - "github.com/arduino/arduino-cli/commands/config" "github.com/arduino/arduino-cli/commands/generatedocs" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" From 8190986a790b195b838108692ff3ac15f4a9adc8 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 6 Jun 2019 12:34:34 +0200 Subject: [PATCH 2/5] move generatedocs under cli --- {commands => cli}/generatedocs/generatedocs.go | 0 cli/root/root.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {commands => cli}/generatedocs/generatedocs.go (100%) diff --git a/commands/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go similarity index 100% rename from commands/generatedocs/generatedocs.go rename to cli/generatedocs/generatedocs.go diff --git a/cli/root/root.go b/cli/root/root.go index 90905c64d7e..20c6aff6e62 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -28,11 +28,11 @@ import ( "github.com/arduino/arduino-cli/cli/config" "github.com/arduino/arduino-cli/cli/core" "github.com/arduino/arduino-cli/cli/daemon" + "github.com/arduino/arduino-cli/cli/generatedocs" "github.com/arduino/arduino-cli/cli/lib" "github.com/arduino/arduino-cli/cli/sketch" "github.com/arduino/arduino-cli/cli/upload" "github.com/arduino/arduino-cli/cli/version" - "github.com/arduino/arduino-cli/commands/generatedocs" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" paths "github.com/arduino/go-paths-helper" From 79e78524176eed839b24d09e5d25e1a0e78a1cfa Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 6 Jun 2019 13:49:36 +0200 Subject: [PATCH 3/5] move login/logout under cli --- {commands => cli}/login/login.go | 0 {commands => cli}/logout/logout.go | 0 {commands => cli}/validate/validate.go | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {commands => cli}/login/login.go (100%) rename {commands => cli}/logout/logout.go (100%) rename {commands => cli}/validate/validate.go (100%) diff --git a/commands/login/login.go b/cli/login/login.go similarity index 100% rename from commands/login/login.go rename to cli/login/login.go diff --git a/commands/logout/logout.go b/cli/logout/logout.go similarity index 100% rename from commands/logout/logout.go rename to cli/logout/logout.go diff --git a/commands/validate/validate.go b/cli/validate/validate.go similarity index 100% rename from commands/validate/validate.go rename to cli/validate/validate.go From 8a0d1dc497fc6a4059456832e5d32b785b5e8375 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 6 Jun 2019 15:17:19 +0200 Subject: [PATCH 4/5] removed unused commands --- cli/login/login.go | 144 --------------------------------------- cli/logout/logout.go | 85 ----------------------- cli/validate/validate.go | 77 --------------------- 3 files changed, 306 deletions(-) delete mode 100644 cli/login/login.go delete mode 100644 cli/logout/logout.go delete mode 100644 cli/validate/validate.go diff --git a/cli/login/login.go b/cli/login/login.go deleted file mode 100644 index 34dc16fc495..00000000000 --- a/cli/login/login.go +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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 login - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - "syscall" - - "github.com/arduino/arduino-cli/auth" - "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/bgentry/go-netrc/netrc" - homedir "github.com/mitchellh/go-homedir" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "golang.org/x/crypto/ssh/terminal" -) - -// InitCommand prepares the command. -func InitCommand() *cobra.Command { - loginCommand := &cobra.Command{ - Use: "login [username] [password]", - Short: "Creates default credentials for an Arduino Create Session.", - Long: "Creates default credentials for an Arduino Create Session.", - Example: "" + - " " + cli.AppName + " login # Asks for all credentials.\n" + - " " + cli.AppName + " login myUser MySecretPassword # Provide all credentials.\n" + - " " + cli.AppName + " login myUser # Asks for just the password instead of having it in clear.", - Args: cobra.RangeArgs(0, 2), - Run: run, - } - return loginCommand -} - -func run(cmd *cobra.Command, args []string) { - logrus.Info("Executing `arduino login`") - - userEmpty, passwordEmpty := true, true - if len(args) > 0 { - userEmpty = false - if len(args) == 2 { - passwordEmpty = false - } - } - isTextMode := formatter.IsCurrentFormat("text") - if !isTextMode && (userEmpty || passwordEmpty) { - formatter.PrintErrorMessage("User and password must be specified outside of text format.") - return - } - - var user, password string - logrus.Info("Using/Asking credentials") - if userEmpty { - fmt.Print("Username: ") - fmt.Scanln(&user) - } else { - user = args[0] - } - // Username is always lowercase. - user = strings.ToLower(user) - - if passwordEmpty { - fmt.Print("Password: ") - pass, err := terminal.ReadPassword(int(syscall.Stdin)) // nolint:unconvert - if err != nil { - formatter.PrintError(err, "Cannot read password, login aborted.") - return - } - password = string(pass) - fmt.Println() - } else { - password = args[1] - } - - logrus.Info("Getting ~/.netrc file") - - // Save into netrc. - netRCHome, err := homedir.Dir() - if err != nil { - formatter.PrintError(err, "Cannot get current home directory.") - os.Exit(cli.ErrGeneric) - } - - netRCFile := filepath.Join(netRCHome, ".netrc") - file, err := os.OpenFile(netRCFile, os.O_RDONLY|os.O_CREATE, 0600) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - return - } - defer file.Close() - netRC, err := netrc.Parse(file) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - os.Exit(cli.ErrGeneric) - } - - logrus.Info("Trying to login") - - authConf := auth.New() - - token, err := authConf.Token(user, password) - if err != nil { - formatter.PrintError(err, "Cannot login.") - os.Exit(cli.ErrNetwork) - } - - netRC.RemoveMachine("arduino.cc") - netRC.NewMachine("arduino.cc", user, token.Access, token.Refresh) - content, err := netRC.MarshalText() - if err != nil { - formatter.PrintError(err, "Cannot parse new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - err = ioutil.WriteFile(netRCFile, content, 0600) - if err != nil { - formatter.PrintError(err, "Cannot write new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - formatter.PrintResult("" + - "Successfully logged into the system.\n" + - "The session will continue to be refreshed with every call of the CLI and will expire if not used.") - logrus.Info("Done") -} diff --git a/cli/logout/logout.go b/cli/logout/logout.go deleted file mode 100644 index 34e6a2b6041..00000000000 --- a/cli/logout/logout.go +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 logout - -import ( - "io/ioutil" - "os" - "path/filepath" - - "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/bgentry/go-netrc/netrc" - homedir "github.com/mitchellh/go-homedir" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -// InitCommand prepares the command. -func InitCommand() *cobra.Command { - logoutCommand := &cobra.Command{ - Use: "logout", - Short: "Clears credentials for the Arduino Create Session.", - Long: "Clears credentials for the Arduino Create Session.", - Example: " " + cli.AppName + " logout", - Args: cobra.NoArgs, - Run: run, - } - return logoutCommand -} - -func run(cmd *cobra.Command, args []string) { - logrus.Info("Executing `arduino logout`") - - logrus.Info("Getting ~/.netrc file") - netRCHome, err := homedir.Dir() - if err != nil { - formatter.PrintError(err, "Cannot get current home directory.") - os.Exit(cli.ErrGeneric) - } - - netRCFile := filepath.Join(netRCHome, ".netrc") - file, err := os.OpenFile(netRCFile, os.O_RDONLY|os.O_CREATE, 0600) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - return - } - defer file.Close() - - netRC, err := netrc.Parse(file) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - os.Exit(cli.ErrGeneric) - } - - netRC.RemoveMachine("arduino.cc") - content, err := netRC.MarshalText() - if err != nil { - formatter.PrintError(err, "Cannot parse new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - err = ioutil.WriteFile(netRCFile, content, 0600) - if err != nil { - formatter.PrintError(err, "Cannot write new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - formatter.PrintResult("Successfully logged out.") - logrus.Info("Done") -} diff --git a/cli/validate/validate.go b/cli/validate/validate.go deleted file mode 100644 index b4037f8def9..00000000000 --- a/cli/validate/validate.go +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 validate - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/arduino/arduino-cli/arduino/resources" - "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -// InitCommand prepares the command. -func InitCommand() *cobra.Command { - var validateCommand = &cobra.Command{ - Use: "validate", - Short: "Validates Arduino installation.", - Long: "Checks installed cores and tools for corruption.", - Example: " " + cli.AppName + " validate", - Args: cobra.NoArgs, - Run: run, - } - return validateCommand -} - -func run(cmd *cobra.Command, args []string) { - logrus.Info("Executing `arduino validate`") - packagesDir := cli.Config.PackagesDir().String() - err := filepath.Walk(packagesDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - return nil - } - relativePath, err := filepath.Rel(packagesDir, path) - if err != nil { - return err - } - pathParts := strings.Split(relativePath, string(filepath.Separator)) - if len(pathParts) == 4 { - isValid, err := resources.CheckDirChecksum(path) - if err != nil { - return err - } - if !isValid { - formatter.PrintErrorMessage(fmt.Sprintf("Corrupted %s", path)) - } - return filepath.SkipDir - } - return nil - }) - if err != nil { - formatter.PrintError(err, "Failed to perform validation.") - os.Exit(cli.ErrBadCall) - } -} From 6e08457aa452e9d11f15b115fb0c09fe0038c95a Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 6 Jun 2019 15:35:32 +0200 Subject: [PATCH 5/5] update dep --- Gopkg.lock | 9 --------- Gopkg.toml | 4 ---- 2 files changed, 13 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 77bbb77571f..1ac80bd420f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -60,14 +60,6 @@ pruneopts = "UT" revision = "ed041402e83b924251a5d65b4dfeb727c480c359" -[[projects]] - branch = "master" - digest = "1:37011b20a70e205b93ebea5287e1afa5618db54bf3998c36ff5a8e4b146a170a" - name = "github.com/bgentry/go-netrc" - packages = ["netrc"] - pruneopts = "UT" - revision = "9fd32a8b3d3d3f9d43c341bfe098430e07609480" - [[projects]] digest = "1:d8abdc866ebbe05fa3bce50863e23afd4c73c804b90c908caa864e86df1db8a1" name = "github.com/bouk/monkey" @@ -527,7 +519,6 @@ "github.com/arduino/go-paths-helper", "github.com/arduino/go-properties-orderedmap", "github.com/arduino/go-win32-utils", - "github.com/bgentry/go-netrc/netrc", "github.com/bouk/monkey", "github.com/codeclysm/extract", "github.com/fatih/color", diff --git a/Gopkg.toml b/Gopkg.toml index aa7c7979dbe..d46748b7972 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -47,10 +47,6 @@ branch = "master" name = "go.bug.st/serial.v1" -[[constraint]] - branch = "master" - name = "github.com/bgentry/go-netrc" - [[constraint]] branch = "master" name = "github.com/mitchellh/go-homedir"