@@ -18,6 +18,7 @@ package arguments
1818import (
1919 "os"
2020
21+ "github.com/arduino/arduino-cli/arduino/sketch"
2122 "github.com/arduino/arduino-cli/cli/errorcodes"
2223 "github.com/arduino/arduino-cli/cli/feedback"
2324 "github.com/arduino/go-paths-helper"
@@ -26,16 +27,40 @@ import (
2627
2728// InitSketchPath returns an instance of paths.Path pointing to sketchPath.
2829// 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
3242 }
43+ WarnDeprecatedFiles (sketchPath )
44+ return sketchPath
45+ }
3346
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 )
3550 if err != nil {
36- feedback .Errorf (tr ("Couldn't get current working directory : %v" ), err )
51+ feedback .Errorf (tr ("Error creating sketch : %v" ), err )
3752 os .Exit (errorcodes .ErrGeneric )
3853 }
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+ }
4166}
0 commit comments