Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --no-check-for-updates in version command #2272

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions internal/cli/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
Expand Down