From 5a13de3283c5382b288962c684c9a0f7131372bf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 21 Aug 2023 16:51:34 +0200 Subject: [PATCH] Added --no-check-for-updates in 'version' command --- internal/cli/version/version.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/cli/version/version.go b/internal/cli/version/version.go index e445d751fc8..30250eec078 100644 --- a/internal/cli/version/version.go +++ b/internal/cli/version/version.go @@ -33,18 +33,20 @@ var tr = i18n.Tr // NewCommand created a new `version` command func NewCommand() *cobra.Command { + var noUpdateCheck bool versionCommand := &cobra.Command{ Use: "version", Short: tr("Shows version number of Arduino CLI."), Long: tr("Shows the version number of Arduino CLI which is installed on your system."), Example: " " + os.Args[0] + " version", Args: cobra.NoArgs, - Run: runVersionCommand, + Run: func(cmd *cobra.Command, args []string) { runVersionCommand(noUpdateCheck) }, } + versionCommand.Flags().BoolVar(&noUpdateCheck, "no-check-for-updates", false, tr("Do not check for updates, just print the current version.")) return versionCommand } -func runVersionCommand(cmd *cobra.Command, args []string) { +func runVersionCommand(noUpdateCheck bool) { logrus.Info("Executing `arduino-cli version`") info := version.VersionInfo @@ -59,15 +61,17 @@ func runVersionCommand(cmd *cobra.Command, args []string) { if err != nil { feedback.Fatal(fmt.Sprintf("Error parsing current version: %s", err), feedback.ErrGeneric) } - latestVersion := updater.CheckForUpdate(currentVersion) + + var latestVersion *semver.Version + if !noUpdateCheck { + latestVersion = updater.CheckForUpdate(currentVersion) + } if feedback.GetFormat() != feedback.Text && latestVersion != nil { // Set this only we managed to get the latest version info.LatestVersion = latestVersion.String() } - feedback.PrintResult(info) - if feedback.GetFormat() == feedback.Text && latestVersion != nil { updater.NotifyNewVersionIsAvailable(latestVersion.String()) }