@@ -18,6 +18,7 @@ package arguments
18
18
import (
19
19
"os"
20
20
21
+ "github.com/arduino/arduino-cli/arduino/sketch"
21
22
"github.com/arduino/arduino-cli/cli/errorcodes"
22
23
"github.com/arduino/arduino-cli/cli/feedback"
23
24
"github.com/arduino/go-paths-helper"
@@ -26,16 +27,40 @@ import (
26
27
27
28
// InitSketchPath returns an instance of paths.Path pointing to sketchPath.
28
29
// If sketchPath is an empty string returns the current working directory.
29
- func InitSketchPath (sketchPath string ) * paths.Path {
30
- if sketchPath != "" {
31
- return paths .New (sketchPath )
30
+ // In both cases it warns the user if he's using deprecated files
31
+ func InitSketchPath (path string ) (sketchPath * paths.Path ) {
32
+ if path != "" {
33
+ sketchPath = paths .New (path )
34
+ } else {
35
+ wd , err := paths .Getwd ()
36
+ if err != nil {
37
+ feedback .Errorf (tr ("Couldn't get current working directory: %v" ), err )
38
+ os .Exit (errorcodes .ErrGeneric )
39
+ }
40
+ logrus .Infof ("Reading sketch from dir: %s" , wd )
41
+ sketchPath = wd
32
42
}
43
+ WarnDeprecatedFiles (sketchPath )
44
+ return sketchPath
45
+ }
33
46
34
- wd , err := paths .Getwd ()
47
+ // NewSketch is a helper function useful to create a sketch instance
48
+ func NewSketch (sketchPath * paths.Path ) * sketch.Sketch {
49
+ sketch , err := sketch .New (sketchPath )
35
50
if err != nil {
36
- feedback .Errorf (tr ("Couldn't get current working directory : %v" ), err )
51
+ feedback .Errorf (tr ("Error creating sketch : %v" ), err )
37
52
os .Exit (errorcodes .ErrGeneric )
38
53
}
39
- logrus .Infof ("Reading sketch from dir: %s" , wd )
40
- return wd
54
+ return sketch
55
+ }
56
+
57
+ // WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
58
+ func WarnDeprecatedFiles (sketchPath * paths.Path ) {
59
+ // .pde files are still supported but deprecated, this warning urges the user to rename them
60
+ if files := sketch .CheckForPdeFiles (sketchPath ); len (files ) > 0 {
61
+ feedback .Error (tr ("Sketches with .pde extension are deprecated, please rename the following files to .ino:" ))
62
+ for _ , f := range files {
63
+ feedback .Error (f )
64
+ }
65
+ }
41
66
}
0 commit comments