@@ -27,6 +27,8 @@ import (
2727 "github.com/arduino/arduino-cli/cli/output"
2828 "github.com/arduino/arduino-cli/commands/board"
2929 rpc "github.com/arduino/arduino-cli/rpc/commands"
30+ "github.com/arduino/go-paths-helper"
31+ "github.com/sirupsen/logrus"
3032 "github.com/spf13/cobra"
3133)
3234
@@ -52,18 +54,37 @@ var attachFlags struct {
5254
5355func runAttachCommand (cmd * cobra.Command , args []string ) {
5456 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 )
5863 }
64+
5965 _ , err := board .Attach (context .Background (), & rpc.BoardAttachReq {
6066 Instance : instance ,
6167 BoardUri : args [0 ],
62- SketchPath : path ,
68+ SketchPath : path . String () ,
6369 SearchTimeout : attachFlags .searchTimeout ,
6470 }, output .TaskProgress ())
6571 if err != nil {
6672 feedback .Errorf ("Attach board error: %v" , err )
6773 os .Exit (errorcodes .ErrGeneric )
6874 }
6975}
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