Skip to content

Commit a4cb726

Browse files
chore: refactor internal tool structure (#37)
* Remove callback function and download archives automatically * Create client inside DownloadImage function * Move interaction with user closer to cobra function * Reorganize project structure * Run task fmt
1 parent 9790b3e commit a4cb726

31 files changed

+148
-156
lines changed

Taskfile.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ tasks:
6565
vars:
6666
VERSION: "{{.VERSION }}"
6767
cmds:
68-
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli .
68+
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli ./cmd/arduino-flasher-cli/
6969
platforms: [linux, darwin]
70-
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli.exe .
70+
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli.exe ./cmd/arduino-flasher-cli/
7171
platforms: [windows]
7272

7373
build:artifacts:
7474
desc: Prepare the arduino-flasher-cli artifacts
7575
internal: true
7676
status:
77-
- test -f ./updater/artifacts/resources_darwin_amd64/qdl
78-
- test -f ./updater/artifacts/resources_darwin_arm64/qdl
79-
- test -f ./updater/artifacts/resources_linux_amd64/qdl
80-
- test -f ./updater/artifacts/resources_linux_arm64/qdl
81-
- test -f ./updater/artifacts/resources_windows_amd64/qdl.exe
82-
cmd: sh ./updater/artifacts/download_resources.sh
77+
- test -f ./internal/updater/artifacts/resources_darwin_amd64/qdl
78+
- test -f ./internal/updater/artifacts/resources_darwin_arm64/qdl
79+
- test -f ./internal/updater/artifacts/resources_linux_amd64/qdl
80+
- test -f ./internal/updater/artifacts/resources_linux_arm64/qdl
81+
- test -f ./internal/updater/artifacts/resources_windows_amd64/qdl.exe
82+
cmd: sh ./internal/updater/artifacts/download_resources.sh
8383

8484
release:
8585
desc: Create a tag on the current commit and push it to the remote to create the release

download.go renamed to cmd/arduino-flasher-cli/download/download.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package main
16+
package download
1717

1818
import (
1919
"context"
@@ -22,12 +22,12 @@ import (
2222
"github.com/arduino/go-paths-helper"
2323
"github.com/spf13/cobra"
2424

25-
"github.com/arduino/arduino-flasher-cli/feedback"
26-
"github.com/arduino/arduino-flasher-cli/i18n"
27-
"github.com/arduino/arduino-flasher-cli/updater"
25+
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
26+
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
27+
"github.com/arduino/arduino-flasher-cli/internal/updater"
2828
)
2929

30-
func newDownloadCmd() *cobra.Command {
30+
func NewDownloadCmd() *cobra.Command {
3131
var destDir string
3232
cmd := &cobra.Command{
3333
Use: "download",
@@ -52,8 +52,7 @@ func runDownloadCommand(ctx context.Context, args []string, destDir string) {
5252
feedback.Fatal(i18n.Tr("error: %s is not a directory. Please, select an existing directory.", destDir), feedback.ErrBadArgument)
5353
}
5454

55-
client := updater.NewClient()
56-
downloadPath, _, err := updater.DownloadImage(ctx, client, targetVersion, nil, true, downloadPath)
55+
downloadPath, _, err := updater.DownloadImage(ctx, targetVersion, downloadPath)
5756
if err != nil {
5857
feedback.Fatal(i18n.Tr("error downloading the image: %v", err), feedback.ErrBadArgument)
5958
}

drivers.go renamed to cmd/arduino-flasher-cli/drivers/drivers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package main
16+
package drivers
1717

1818
import (
1919
"github.com/spf13/cobra"
2020

21-
"github.com/arduino/arduino-flasher-cli/feedback"
22-
"github.com/arduino/arduino-flasher-cli/i18n"
21+
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
22+
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
2323
)
2424

25-
func newInstallDriversCmd() *cobra.Command {
25+
func NewInstallDriversCmd() *cobra.Command {
2626
cmd := &cobra.Command{
2727
Use: "install-drivers",
2828
Hidden: true,

drivers_others.go renamed to cmd/arduino-flasher-cli/drivers/drivers_others.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
//go:build !windows
1717

18-
package main
18+
package drivers
1919

2020
// installDrivers is a no-op on non-Windows platforms
2121
func installDrivers() error {

drivers_windows.go renamed to cmd/arduino-flasher-cli/drivers/drivers_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package main
16+
package drivers
1717

1818
import (
1919
"embed"
@@ -23,7 +23,7 @@ import (
2323
"github.com/arduino/go-paths-helper"
2424
)
2525

26-
//go:embed drivers
26+
//go:embed src
2727
var drivers embed.FS
2828

2929
// installDrivers installs the Windows driver using dpinst.exe. This requires

drivers/dpinst-amd64.exe renamed to cmd/arduino-flasher-cli/drivers/src/dpinst-amd64.exe

File renamed without changes.

drivers/dpinst-x86.exe renamed to cmd/arduino-flasher-cli/drivers/src/dpinst-x86.exe

File renamed without changes.

drivers/unoq.cat renamed to cmd/arduino-flasher-cli/drivers/src/unoq.cat

File renamed without changes.

drivers/unoq.inf renamed to cmd/arduino-flasher-cli/drivers/src/unoq.inf

File renamed without changes.

flash.go renamed to cmd/arduino-flasher-cli/flash/flash.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package main
16+
package flash
1717

1818
import (
1919
"context"
20+
"fmt"
2021
"os"
2122
"runtime"
23+
"strings"
2224

2325
"github.com/arduino/go-paths-helper"
2426
runas "github.com/arduino/go-windows-runas"
2527
"github.com/spf13/cobra"
2628

27-
"github.com/arduino/arduino-flasher-cli/feedback"
28-
"github.com/arduino/arduino-flasher-cli/i18n"
29-
"github.com/arduino/arduino-flasher-cli/updater"
29+
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
30+
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
31+
"github.com/arduino/arduino-flasher-cli/internal/updater"
3032
)
3133

32-
func newFlashCmd() *cobra.Command {
34+
func NewFlashCmd() *cobra.Command {
3335
var forceYes bool
3436
var tempDir string
3537
appCmd := &cobra.Command{
@@ -95,8 +97,25 @@ func runFlashCommand(ctx context.Context, args []string, forceYes bool, tempDir
9597
feedback.Fatal(i18n.Tr("could not find image absolute path: %v", err), feedback.ErrBadArgument)
9698
}
9799

100+
if !forceYes {
101+
feedback.Print("\nWARNING: flashing a new Linux image on the board will erase any existing data you have on it.")
102+
feedback.Printf("Do you want to proceed and flash %s on the board? (yes/no)", args[0])
103+
104+
var yesInput string
105+
_, err := fmt.Scanf("%s\n", &yesInput)
106+
if err != nil {
107+
feedback.Fatal(err.Error(), feedback.ErrBadArgument)
108+
}
109+
yes := strings.ToLower(yesInput) == "yes" || strings.ToLower(yesInput) == "y"
110+
111+
if !yes {
112+
return
113+
}
114+
}
115+
98116
err = updater.Flash(ctx, imagePath, args[0], forceYes, tempDir)
99117
if err != nil {
100118
feedback.Fatal(i18n.Tr("error flashing the board: %v", err), feedback.ErrBadArgument)
101119
}
120+
feedback.Print("\nThe board has been successfully flashed. You can now power-cycle the board (unplug and re-plug). Remember to remove the jumper.")
102121
}

0 commit comments

Comments
 (0)