Skip to content

Commit 282e365

Browse files
Apply review suggestions
1 parent fa879d2 commit 282e365

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

check_for_updates.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,52 @@ import (
2424
"github.com/fatih/color"
2525
semver "go.bug.st/relaxed-semver"
2626

27-
"github.com/arduino/arduino-flasher-cli/feedback"
2827
"github.com/arduino/arduino-flasher-cli/i18n"
2928
"github.com/arduino/arduino-flasher-cli/updater"
3029
)
3130

32-
type FlasherRelease struct {
33-
TagName string `json:"tag_name"`
34-
}
35-
36-
func checkForUpdates() error {
31+
func checkForUpdates() (string, error) {
3732
currentVersion, err := semver.Parse(Version)
3833
if err != nil {
39-
return err
34+
return "", err
4035
}
4136

4237
c := updater.NewClient()
4338
req, err := http.NewRequest("GET", "https://api.github.com/repos/arduino/arduino-flasher-cli/releases/latest", nil)
4439
if err != nil {
45-
return err
40+
return "", err
4641
}
4742
resp, err := c.HTTPClient.Do(req)
4843
if err != nil {
49-
return err
44+
return "", err
5045
}
5146
defer resp.Body.Close()
5247

53-
var release FlasherRelease
48+
var release struct {
49+
TagName string `json:"tag_name"`
50+
}
51+
5452
err = json.NewDecoder(resp.Body).Decode(&release)
5553
if err != nil {
56-
return err
54+
return "", err
5755
}
5856

5957
release.TagName = strings.TrimPrefix(release.TagName, "v")
6058
latestVersion, err := semver.Parse(release.TagName)
6159
if err != nil {
62-
return err
60+
return "", err
6361
}
6462

6563
// Do nothing if the Arduino Flasher CLI is up to date
6664
if currentVersion.GreaterThanOrEqual(latestVersion) {
67-
return nil
65+
return "", nil
6866
}
6967

7068
msg := fmt.Sprintf("\n\n%s %s → %s\n%s",
7169
color.YellowString(i18n.Tr("A new release of Arduino Flasher CLI is available:")),
7270
color.CyanString(currentVersion.String()),
7371
color.CyanString(latestVersion.String()),
7472
color.YellowString("https://www.arduino.cc/en/software/#flasher-tool"))
75-
feedback.Print(msg)
7673

77-
return nil
74+
return msg, nil
7875
}

download.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ func runDownloadCommand(args []string, destDir string) {
5656
feedback.Fatal(i18n.Tr("error downloading the image: %v", err), feedback.ErrBadArgument)
5757
}
5858

59-
err = checkForUpdates()
59+
msg, err := checkForUpdates()
6060
if err != nil {
6161
feedback.Warning("\n\nfailed to check for updates: " + err.Error())
6262
}
63+
if msg != "" {
64+
feedback.Print(msg)
65+
}
6366
}

flash.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ func runFlashCommand(ctx context.Context, args []string, forceYes bool) {
9797
feedback.Fatal(i18n.Tr("error flashing the board: %v", err), feedback.ErrBadArgument)
9898
}
9999

100-
err = checkForUpdates()
100+
msg, err := checkForUpdates()
101101
if err != nil {
102102
feedback.Warning("\n\nfailed to check for updates: " + err.Error())
103103
}
104+
if msg != "" {
105+
feedback.Print(msg)
106+
}
104107
}

list.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ func runListCommand() {
4646
}
4747

4848
feedback.PrintResult(listResult{Latest: manifest.Latest, Releases: manifest.Releases})
49-
err = checkForUpdates()
49+
msg, err := checkForUpdates()
5050
if err != nil {
5151
feedback.Warning("\n\nfailed to check for updates: " + err.Error())
5252
}
53+
if msg != "" {
54+
feedback.Print(msg)
55+
}
5356
}
5457

5558
type listResult struct {

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ func main() {
6060
Short: "Print the version number of Arduino Flasher CLI",
6161
Run: func(cmd *cobra.Command, args []string) {
6262
feedback.Print("Arduino Flasher CLI " + Version)
63-
err := checkForUpdates()
63+
msg, err := checkForUpdates()
6464
if err != nil {
6565
feedback.Warning("\n\nfailed to check for updates: " + err.Error())
6666
}
67+
if msg != "" {
68+
feedback.Print(msg)
69+
}
6770
},
6871
})
6972

0 commit comments

Comments
 (0)