Skip to content

Commit 8e048b0

Browse files
Move WarnDeprecatedFiles to commands/sketch
1 parent 3f5c0eb commit 8e048b0

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

Diff for: commands/sketch/warn_deprecated.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package sketch
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/arduino/arduino-cli/arduino/sketch"
22+
paths "github.com/arduino/go-paths-helper"
23+
)
24+
25+
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
26+
func WarnDeprecatedFiles(sketchPath *paths.Path) string {
27+
// .pde files are still supported but deprecated, this warning urges the user to rename them
28+
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
29+
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
30+
for _, f := range files {
31+
msg += fmt.Sprintf("\n - %s", f)
32+
}
33+
return msg
34+
}
35+
return ""
36+
}

Diff for: internal/cli/arguments/sketch.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
package arguments
1717

1818
import (
19-
"fmt"
20-
21-
"github.com/arduino/arduino-cli/arduino/sketch"
19+
sk "github.com/arduino/arduino-cli/commands/sketch"
2220
"github.com/arduino/arduino-cli/internal/cli/feedback"
2321
"github.com/arduino/go-paths-helper"
2422
"github.com/sirupsen/logrus"
@@ -38,18 +36,8 @@ func InitSketchPath(path string) (sketchPath *paths.Path) {
3836
logrus.Infof("Reading sketch from dir: %s", wd)
3937
sketchPath = wd
4038
}
41-
WarnDeprecatedFiles(sketchPath)
42-
return sketchPath
43-
}
44-
45-
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
46-
func WarnDeprecatedFiles(sketchPath *paths.Path) {
47-
// .pde files are still supported but deprecated, this warning urges the user to rename them
48-
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
49-
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
50-
for _, f := range files {
51-
msg += fmt.Sprintf("\n - %s", f)
52-
}
39+
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
5340
feedback.Warning(msg)
5441
}
42+
return sketchPath
5543
}

Diff for: internal/cli/sketch/archive.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"os"
2222

2323
sk "github.com/arduino/arduino-cli/commands/sketch"
24-
"github.com/arduino/arduino-cli/internal/cli/arguments"
2524
"github.com/arduino/arduino-cli/internal/cli/feedback"
2625
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2726
"github.com/arduino/go-paths-helper"
@@ -61,7 +60,9 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
6160
sketchPath = paths.New(args[0])
6261
}
6362

64-
arguments.WarnDeprecatedFiles(sketchPath)
63+
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
64+
feedback.Warning(msg)
65+
}
6566

6667
archivePath := ""
6768
if len(args) == 2 {

Diff for: internal/cli/upload/upload.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func runUploadCommand(command *cobra.Command, args []string) {
8686
}
8787
sketchPath := arguments.InitSketchPath(path)
8888

89-
if importDir == "" && importFile == "" {
90-
arguments.WarnDeprecatedFiles(sketchPath)
89+
if msg := sk.WarnDeprecatedFiles(sketchPath); importDir == "" && importFile == "" && msg != "" {
90+
feedback.Warning(msg)
9191
}
9292

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

0 commit comments

Comments
 (0)