@@ -27,6 +27,8 @@ import (
27
27
"github.com/arduino/arduino-cli/cli/output"
28
28
"github.com/arduino/arduino-cli/commands/board"
29
29
rpc "github.com/arduino/arduino-cli/rpc/commands"
30
+ "github.com/arduino/go-paths-helper"
31
+ "github.com/sirupsen/logrus"
30
32
"github.com/spf13/cobra"
31
33
)
32
34
@@ -52,18 +54,37 @@ var attachFlags struct {
52
54
53
55
func runAttachCommand (cmd * cobra.Command , args []string ) {
54
56
instance := instance .CreateInstance ()
55
- var path string
56
- if len (args ) > 0 {
57
- path = args [1 ]
57
+
58
+ var path * paths.Path
59
+ if len (args ) > 1 {
60
+ path = paths .New (args [1 ])
61
+ } else {
62
+ path = initSketchPath (path )
58
63
}
64
+
59
65
_ , err := board .Attach (context .Background (), & rpc.BoardAttachReq {
60
66
Instance : instance ,
61
67
BoardUri : args [0 ],
62
- SketchPath : path ,
68
+ SketchPath : path . String () ,
63
69
SearchTimeout : attachFlags .searchTimeout ,
64
70
}, output .TaskProgress ())
65
71
if err != nil {
66
72
feedback .Errorf ("Attach board error: %v" , err )
67
73
os .Exit (errorcodes .ErrGeneric )
68
74
}
69
75
}
76
+
77
+ // initSketchPath returns the current working directory
78
+ func initSketchPath (sketchPath * paths.Path ) * paths.Path {
79
+ if sketchPath != nil {
80
+ return sketchPath
81
+ }
82
+
83
+ wd , err := paths .Getwd ()
84
+ if err != nil {
85
+ feedback .Errorf ("Couldn't get current working directory: %v" , err )
86
+ os .Exit (errorcodes .ErrGeneric )
87
+ }
88
+ logrus .Infof ("Reading sketch from dir: %s" , wd )
89
+ return wd
90
+ }
0 commit comments