@@ -19,14 +19,13 @@ import (
1919 "context"
2020 "os"
2121
22+ "github.com/arduino/arduino-cli/cli/arguments"
2223 "github.com/arduino/arduino-cli/cli/errorcodes"
2324 "github.com/arduino/arduino-cli/cli/feedback"
2425 "github.com/arduino/arduino-cli/cli/instance"
2526 "github.com/arduino/arduino-cli/cli/output"
2627 "github.com/arduino/arduino-cli/commands/board"
2728 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28- "github.com/arduino/go-paths-helper"
29- "github.com/sirupsen/logrus"
3029 "github.com/spf13/cobra"
3130)
3231
@@ -53,35 +52,19 @@ var attachFlags struct {
5352func runAttachCommand (cmd * cobra.Command , args []string ) {
5453 instance := instance .CreateAndInit ()
5554
56- var path * paths. Path
55+ path := ""
5756 if len (args ) > 1 {
58- path = paths .New (args [1 ])
59- } else {
60- path = initSketchPath (path )
57+ path = args [1 ]
6158 }
59+ sketchPath := arguments .InitSketchPath (path )
6260
6361 if _ , err := board .Attach (context .Background (), & rpc.BoardAttachRequest {
6462 Instance : instance ,
6563 BoardUri : args [0 ],
66- SketchPath : path .String (),
64+ SketchPath : sketchPath .String (),
6765 SearchTimeout : attachFlags .searchTimeout ,
6866 }, output .TaskProgress ()); err != nil {
6967 feedback .Errorf ("Attach board error: %v" , err )
7068 os .Exit (errorcodes .ErrGeneric )
7169 }
7270}
73-
74- // initSketchPath returns the current working directory
75- func initSketchPath (sketchPath * paths.Path ) * paths.Path {
76- if sketchPath != nil {
77- return sketchPath
78- }
79-
80- wd , err := paths .Getwd ()
81- if err != nil {
82- feedback .Errorf ("Couldn't get current working directory: %v" , err )
83- os .Exit (errorcodes .ErrGeneric )
84- }
85- logrus .Infof ("Reading sketch from dir: %s" , wd )
86- return wd
87- }
0 commit comments