@@ -20,9 +20,9 @@ import (
2020 "io/ioutil"
2121 "os"
2222 "path/filepath"
23- "strings"
2423
2524 "github.com/arduino/arduino-cli/commands"
25+ "github.com/arduino/arduino-cli/configuration"
2626 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2727)
2828
@@ -35,27 +35,23 @@ void loop() {
3535` )
3636
3737// CreateSketch creates a new sketch
38- func CreateSketch (sketchName string ) (string , string , error ) {
39- // Trim to avoid issues if user creates a sketch adding the .ino extesion to the name
40- trimmedSketchName := strings .TrimSuffix (sketchName , ".ino" )
41- sketchDir , err := filepath .Abs (trimmedSketchName )
42- if err != nil {
43- return "" , "" , err
44- }
38+ func CreateSketch (sketchDir string , sketchName string ) (string , error ) {
4539 if err := os .MkdirAll (sketchDir , os .FileMode (0755 )); err != nil {
46- return "" , "" , err
40+ return "" , err
4741 }
4842 baseSketchName := filepath .Base (sketchDir )
4943 sketchFile := filepath .Join (sketchDir , baseSketchName + ".ino" )
5044 if err := ioutil .WriteFile (sketchFile , emptySketch , os .FileMode (0644 )); err != nil {
51- return "" , "" , err
45+ return "" , err
5246 }
53- return sketchDir , sketchFile , nil
47+ return sketchFile , nil
5448}
5549
5650// NewSketch FIXMEDOC
5751func NewSketch (ctx context.Context , req * rpc.NewSketchRequest ) (* rpc.NewSketchResponse , error ) {
58- _ , sketchFile , err := CreateSketch (req .SketchName )
52+ sketchesDir := configuration .Settings .GetString ("directories.Sketches" );
53+ sketchDir := filepath .Join (sketchesDir , req .SketchName )
54+ sketchFile , err := CreateSketch (sketchDir , req .SketchName )
5955 if err != nil {
6056 return nil , & commands.CantCreateSketchError {Cause : err }
6157 }
0 commit comments