Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move WarnDeprecatedFiles to commands/sketch
  • Loading branch information
MatteoPologruto committed Sep 20, 2023
commit 84f38d42782b2ae554371e1479a7081190d08d61
36 changes: 36 additions & 0 deletions commands/sketch/warn_deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of arduino-cli.
//
// Copyright 2020 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-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 sketch

import (
"fmt"

"github.com/arduino/arduino-cli/arduino/sketch"
paths "github.com/arduino/go-paths-helper"
)

// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
func WarnDeprecatedFiles(sketchPath *paths.Path) string {
// .pde files are still supported but deprecated, this warning urges the user to rename them
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
for _, f := range files {
msg += fmt.Sprintf("\n - %s", f)
}
return msg
}
return ""
}
18 changes: 3 additions & 15 deletions internal/cli/arguments/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package arguments

import (
"fmt"

"github.com/arduino/arduino-cli/arduino/sketch"
sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
Expand All @@ -38,18 +36,8 @@ func InitSketchPath(path string) (sketchPath *paths.Path) {
logrus.Infof("Reading sketch from dir: %s", wd)
sketchPath = wd
}
WarnDeprecatedFiles(sketchPath)
return sketchPath
}

// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
func WarnDeprecatedFiles(sketchPath *paths.Path) {
// .pde files are still supported but deprecated, this warning urges the user to rename them
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
for _, f := range files {
msg += fmt.Sprintf("\n - %s", f)
}
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
feedback.Warning(msg)
}
return sketchPath
}
5 changes: 3 additions & 2 deletions internal/cli/sketch/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"

sk "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"
Expand Down Expand Up @@ -61,7 +60,9 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
sketchPath = paths.New(args[0])
}

arguments.WarnDeprecatedFiles(sketchPath)
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
feedback.Warning(msg)
}

archivePath := ""
if len(args) == 2 {
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func runUploadCommand(command *cobra.Command, args []string) {
}
sketchPath := arguments.InitSketchPath(path)

if importDir == "" && importFile == "" {
arguments.WarnDeprecatedFiles(sketchPath)
if msg := sk.WarnDeprecatedFiles(sketchPath); importDir == "" && importFile == "" && msg != "" {
feedback.Warning(msg)
}

sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
Expand Down