Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ tasks:
vars:
VERSION: "{{.VERSION }}"
cmds:
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli .
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli ./cmd/arduino-flasher-cli/
platforms: [linux, darwin]
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli.exe .
- cmd: go build -ldflags "-X main.Version={{.VERSION}}" -v -o ./build/arduino-flasher-cli.exe ./cmd/arduino-flasher-cli/
platforms: [windows]

build:artifacts:
desc: Prepare the arduino-flasher-cli artifacts
internal: true
status:
- test -f ./updater/artifacts/resources_darwin_amd64/qdl
- test -f ./updater/artifacts/resources_darwin_arm64/qdl
- test -f ./updater/artifacts/resources_linux_amd64/qdl
- test -f ./updater/artifacts/resources_linux_arm64/qdl
- test -f ./updater/artifacts/resources_windows_amd64/qdl.exe
cmd: sh ./updater/artifacts/download_resources.sh
- test -f ./internal/updater/artifacts/resources_darwin_amd64/qdl
- test -f ./internal/updater/artifacts/resources_darwin_arm64/qdl
- test -f ./internal/updater/artifacts/resources_linux_amd64/qdl
- test -f ./internal/updater/artifacts/resources_linux_arm64/qdl
- test -f ./internal/updater/artifacts/resources_windows_amd64/qdl.exe
cmd: sh ./internal/updater/artifacts/download_resources.sh

release:
desc: Create a tag on the current commit and push it to the remote to create the release
Expand Down
13 changes: 6 additions & 7 deletions download.go → cmd/arduino-flasher-cli/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package main
package download

import (
"context"
Expand All @@ -22,12 +22,12 @@ import (
"github.com/arduino/go-paths-helper"
"github.com/spf13/cobra"

"github.com/arduino/arduino-flasher-cli/feedback"
"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/updater"
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
"github.com/arduino/arduino-flasher-cli/internal/updater"
)

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

client := updater.NewClient()
downloadPath, _, err := updater.DownloadImage(ctx, client, targetVersion, nil, true, downloadPath)
downloadPath, _, err := updater.DownloadImage(ctx, targetVersion, downloadPath)
if err != nil {
feedback.Fatal(i18n.Tr("error downloading the image: %v", err), feedback.ErrBadArgument)
}
Expand Down
8 changes: 4 additions & 4 deletions drivers.go → cmd/arduino-flasher-cli/drivers/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package main
package drivers

import (
"github.com/spf13/cobra"

"github.com/arduino/arduino-flasher-cli/feedback"
"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
)

func newInstallDriversCmd() *cobra.Command {
func NewInstallDriversCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install-drivers",
Hidden: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//go:build !windows

package main
package drivers

// installDrivers is a no-op on non-Windows platforms
func installDrivers() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package main
package drivers

import (
"embed"
Expand All @@ -23,7 +23,7 @@ import (
"github.com/arduino/go-paths-helper"
)

//go:embed drivers
//go:embed src
var drivers embed.FS

// installDrivers installs the Windows driver using dpinst.exe. This requires
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 24 additions & 5 deletions flash.go → cmd/arduino-flasher-cli/flash/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package main
package flash

import (
"context"
"fmt"
"os"
"runtime"
"strings"

"github.com/arduino/go-paths-helper"
runas "github.com/arduino/go-windows-runas"
"github.com/spf13/cobra"

"github.com/arduino/arduino-flasher-cli/feedback"
"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/updater"
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
"github.com/arduino/arduino-flasher-cli/internal/updater"
)

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

if !forceYes {
feedback.Print("\nWARNING: flashing a new Linux image on the board will erase any existing data you have on it.")
feedback.Printf("Do you want to proceed and flash %s on the board? (yes/no)", args[0])

var yesInput string
_, err := fmt.Scanf("%s\n", &yesInput)
if err != nil {
feedback.Fatal(err.Error(), feedback.ErrBadArgument)
}
yes := strings.ToLower(yesInput) == "yes" || strings.ToLower(yesInput) == "y"

if !yes {
return
}
}

err = updater.Flash(ctx, imagePath, args[0], forceYes, tempDir)
if err != nil {
feedback.Fatal(i18n.Tr("error flashing the board: %v", err), feedback.ErrBadArgument)
}
feedback.Print("\nThe board has been successfully flashed. You can now power-cycle the board (unplug and re-plug). Remember to remove the jumper.")
}
12 changes: 6 additions & 6 deletions list.go → cmd/arduino-flasher-cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package main
package list

import (
"context"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

"github.com/arduino/arduino-flasher-cli/feedback"
"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/tablestyle"
"github.com/arduino/arduino-flasher-cli/updater"
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
"github.com/arduino/arduino-flasher-cli/internal/tablestyle"
"github.com/arduino/arduino-flasher-cli/internal/updater"
)

func newListCmd() *cobra.Command {
func NewListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List the available Linux images",
Expand Down
58 changes: 13 additions & 45 deletions main.go → cmd/arduino-flasher-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ package main

import (
"context"
"fmt"
"log/slog"
"os"

"github.com/fatih/color"
"github.com/spf13/cobra"
"go.bug.st/cleanup"

"github.com/arduino/arduino-flasher-cli/feedback"
"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/cmd/arduino-flasher-cli/download"
"github.com/arduino/arduino-flasher-cli/cmd/arduino-flasher-cli/drivers"
"github.com/arduino/arduino-flasher-cli/cmd/arduino-flasher-cli/flash"
"github.com/arduino/arduino-flasher-cli/cmd/arduino-flasher-cli/list"
"github.com/arduino/arduino-flasher-cli/cmd/arduino-flasher-cli/version"
"github.com/arduino/arduino-flasher-cli/cmd/feedback"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
)

// Version will be set a build time with -ldflags
Expand All @@ -53,51 +56,16 @@ func main() {
rootCmd.PersistentFlags().StringVar(&format, "format", "text", "Output format (text, json)")

rootCmd.AddCommand(
newFlashCmd(),
newInstallDriversCmd(),
newListCmd(),
newDownloadCmd(),
&cobra.Command{
Use: "version",
Short: "Print the version number of Arduino Flasher CLI",
Run: func(cmd *cobra.Command, args []string) {
feedback.PrintResult(versionResult{
Name: "Arduino Flasher CLI",
Version: Version,
})

latest, err := checkForUpdates()
if err != nil {
feedback.Warning(color.YellowString("\n\nFailed to check for updates: "+err.Error()) + "\n")
}
if latest != "" {
msg := fmt.Sprintf("\n\n%s %s → %s\n%s",
color.YellowString(i18n.Tr("A new release of Arduino Flasher CLI is available:")),
color.CyanString(Version),
color.CyanString(latest),
color.YellowString("https://www.arduino.cc/en/software/#flasher-tool"))
feedback.Warning(msg)
}
},
})
flash.NewFlashCmd(),
drivers.NewInstallDriversCmd(),
list.NewListCmd(),
download.NewDownloadCmd(),
version.NewVersionCmd(Version),
)

ctx := context.Background()
ctx, _ = cleanup.InterruptableContext(ctx)
if err := rootCmd.ExecuteContext(ctx); err != nil {
slog.Error(err.Error())
}
}

type versionResult struct {
Name string `json:"name"`
Version string `json:"version"`
}

func (r versionResult) String() string {
resultMessage := fmt.Sprintf("Arduino Flasher CLI version %s", r.Version)
return resultMessage
}

func (r versionResult) Data() interface{} {
return r
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package main
package version

import (
"encoding/json"
Expand All @@ -27,8 +27,8 @@ import (

const maxTime time.Duration = 1 * time.Second

func checkForUpdates() (string, error) {
currentVersion, err := semver.Parse(Version)
func checkForUpdates(version string) (string, error) {
currentVersion, err := semver.Parse(version)
if err != nil {
return "", err
}
Expand Down
67 changes: 67 additions & 0 deletions cmd/arduino-flasher-cli/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This file is part of arduino-flasher-cli.
//
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-flasher-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package version

import (
"fmt"

"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/arduino/arduino-flasher-cli/cmd/feedback"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
)

func NewVersionCmd(version string) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the version number of Arduino Flasher CLI",
Run: func(cmd *cobra.Command, args []string) {
feedback.PrintResult(versionResult{
Name: "Arduino Flasher CLI",
Version: version,
})

latest, err := checkForUpdates(version)
if err != nil {
feedback.Warning(color.YellowString("\n\nFailed to check for updates: "+err.Error()) + "\n")
}
if latest != "" {
msg := fmt.Sprintf("\n\n%s %s → %s\n%s",
color.YellowString(i18n.Tr("A new release of Arduino Flasher CLI is available:")),
color.CyanString(version),
color.CyanString(latest),
color.YellowString("https://www.arduino.cc/en/software/#flasher-tool"))
feedback.Warning(msg)
}
},
}
return cmd
}

type versionResult struct {
Name string `json:"name"`
Version string `json:"version"`
}

func (r versionResult) String() string {
resultMessage := fmt.Sprintf("Arduino Flasher CLI version %s", r.Version)
return resultMessage
}

func (r versionResult) Data() interface{} {
return r
}
File renamed without changes.
2 changes: 1 addition & 1 deletion feedback/feedback.go → cmd/feedback/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"io"
"os"

"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
)

// OutputFormat is an output format
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion feedback/stdio.go → cmd/feedback/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"errors"
"io"

"github.com/arduino/arduino-flasher-cli/i18n"
"github.com/arduino/arduino-flasher-cli/cmd/i18n"
)

// DirectStreams returns the underlying io.Writer to directly stream to
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading