Skip to content

Commit

Permalink
Improved 'sketch archive' parameters check
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jan 5, 2024
1 parent 3764118 commit d3aa662
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
32 changes: 19 additions & 13 deletions internal/cli/sketch/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"fmt"
"os"

sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/internal/cli/arguments"
"github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -55,25 +55,31 @@ func initArchiveCommand() *cobra.Command {
func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
logrus.Info("Executing `arduino-cli sketch archive`")

sketchPath := paths.New(".")
if len(args) >= 1 {
sketchPath = paths.New(args[0])
sketchPathArg := ""
if len(args) > 0 {
sketchPathArg = args[0]
}

archivePath := ""
if len(args) == 2 {
archivePath = args[1]
archivePathArg := ""
if len(args) > 1 {
archivePathArg = args[1]
}

_, err := sk.ArchiveSketch(context.Background(),
sketchPath := arguments.InitSketchPath(sketchPathArg)
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}
feedback.WarnAboutDeprecatedFiles(sk)

if _, err := sketch.ArchiveSketch(context.Background(),
&rpc.ArchiveSketchRequest{
SketchPath: sketchPath.String(),
ArchivePath: archivePath,
ArchivePath: archivePathArg,
IncludeBuildDir: includeBuildDir,
Overwrite: overwrite,
})

if err != nil {
},
); err != nil {
feedback.Fatal(tr("Error archiving: %v", err), feedback.ErrGeneric)
}
}
6 changes: 3 additions & 3 deletions internal/integrationtest/sketch/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ func TestSketchArchiveWithMultipleMainFiles(t *testing.T) {
cli.SetWorkingDir(sketchDir)
_, stderr, err := cli.Run("sketch", "archive")
require.Error(t, err)
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino")
require.NotContains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino")
require.Contains(t, string(stderr), relPath.String())
require.Contains(t, string(stderr), "Error archiving: Can't open sketch: multiple main sketch files found")
require.Contains(t, string(stderr), "Can't open sketch: multiple main sketch files found")
}

func TestSketchArchiveCaseMismatchFails(t *testing.T) {
Expand All @@ -370,7 +370,7 @@ func TestSketchArchiveCaseMismatchFails(t *testing.T) {

_, stderr, err := cli.Run("sketch", "archive", sketchPath.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error archiving: Can't open sketch:")
require.Contains(t, string(stderr), "Can't open sketch:")
}

func TestSketchNewDotArgOverwrite(t *testing.T) {
Expand Down

0 comments on commit d3aa662

Please sign in to comment.