Skip to content

Commit 47ac424

Browse files
Improve tool description, user feedback and add examples
1 parent 85984d3 commit 47ac424

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import (
1919
"context"
2020
"fmt"
2121
"log/slog"
22+
"os"
2223

2324
"github.com/spf13/cobra"
2425
"go.bug.st/cleanup"
25-
26+
2627
"github.com/arduino/arduino-flasher-cli/feedback"
2728
"github.com/arduino/arduino-flasher-cli/i18n"
2829
)
@@ -34,7 +35,9 @@ var format string
3435
func main() {
3536
rootCmd := &cobra.Command{
3637
Use: "arduino-flasher-cli",
37-
Short: "A CLI to update and flash the Debian image",
38+
Short: "A CLI to update your Arduino UNO Q board, by downloading and flashing the latest Arduino Linux image",
39+
Example: " " + os.Args[0] + " flash latest\n" +
40+
" " + os.Args[0] + " list\n",
3841
PersistentPreRun: func(cmd *cobra.Command, args []string) {
3942
format, ok := feedback.ParseOutputFormat(format)
4043
if !ok {

updater/download_image.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,27 @@ type Release struct {
4646
// DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded.
4747
type DownloadConfirmCB func(target string) (bool, error)
4848

49-
func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) (*paths.Path, error) {
49+
func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) (*paths.Path, string, error) {
5050
tmpZip, version, err := DownloadImage(client, targetVersion, upgradeConfirmCb, forceYes)
5151
if err != nil {
52-
return nil, fmt.Errorf("error downloading the image: %v", err)
52+
return nil, "", fmt.Errorf("error downloading the image: %v", err)
5353
}
5454

5555
// Download not confirmed
5656
if tmpZip == nil {
57-
return nil, nil
57+
return nil, "", nil
5858
}
5959

6060
err = ExtractImage(tmpZip, tmpZip.Parent())
6161
if err != nil {
62-
return nil, fmt.Errorf("error extracting the image: %v", err)
62+
return nil, "", fmt.Errorf("error extracting the image: %v", err)
6363
}
6464

6565
imagePath := tmpZip.Parent().Join("arduino-unoq-debian-image-" + version)
66-
return imagePath, nil
66+
if targetVersion == "latest" {
67+
version += "(latest)"
68+
}
69+
return imagePath, version, nil
6770
}
6871

6972
func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) (*paths.Path, string, error) {

updater/flasher.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
3232
if !imagePath.Exist() {
3333
client := NewClient()
3434

35-
tempImagePath, err := DownloadAndExtract(client, version, func(target string) (bool, error) {
35+
tempImagePath, v, err := DownloadAndExtract(client, version, func(target string) (bool, error) {
3636
feedback.Printf("Found Debian image version: %s", target)
3737
feedback.Printf("Do you want to download it? (yes/no)")
3838

@@ -56,6 +56,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
5656

5757
defer tempImagePath.Parent().RemoveAll()
5858

59+
version = v
5960
imagePath = tempImagePath
6061
} else if !imagePath.IsDir() {
6162
temp, err := GetTempDir("extract-")
@@ -77,7 +78,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
7778
imagePath = tempContent[0]
7879
}
7980

80-
return FlashBoard(ctx, imagePath.String(), func(target string) (bool, error) {
81+
return FlashBoard(ctx, imagePath.String(), version, func(target string) (bool, error) {
8182
feedback.Print("\nWARNING: flashing a new Linux image on the board will erase any existing data you have on it.")
8283
feedback.Printf("Do you want to procede and flash %s on the board? (yes/no)", target)
8384

@@ -91,9 +92,9 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
9192
}, forceYes)
9293
}
9394

94-
func FlashBoard(ctx context.Context, downloadedImagePath string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) error {
95+
func FlashBoard(ctx context.Context, downloadedImagePath string, version string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) error {
9596
if !forceYes {
96-
res, err := upgradeConfirmCb(downloadedImagePath)
97+
res, err := upgradeConfirmCb(version)
9798
if err != nil {
9899
return err
99100
}
@@ -152,5 +153,7 @@ func FlashBoard(ctx context.Context, downloadedImagePath string, upgradeConfirmC
152153
return err
153154
}
154155

156+
feedback.Print("\nThe board has been successfully flashed. You can now power-cycle the board (unplug and re-plug). Remember to remove the jumper.")
157+
155158
return nil
156159
}

0 commit comments

Comments
 (0)