Skip to content

Commit 269832b

Browse files
committed
#1456 - Avoid using hardcoded extension (address comment).
1 parent 53f3bf4 commit 269832b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Diff for: cli/sketch/new.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121
"strings"
2222

23+
"github.com/arduino/arduino-cli/arduino/globals"
2324
"github.com/arduino/arduino-cli/cli/errorcodes"
2425
"github.com/arduino/arduino-cli/cli/feedback"
2526
sk "github.com/arduino/arduino-cli/commands/sketch"
@@ -41,7 +42,7 @@ func initNewCommand() *cobra.Command {
4142
func runNewCommand(cmd *cobra.Command, args []string) {
4243
// Trim to avoid issues if user creates a sketch adding the .ino extesion to the name
4344
sketchName := args[0]
44-
trimmedSketchName := strings.TrimSuffix(sketchName, ".ino")
45+
trimmedSketchName := strings.TrimSuffix(sketchName, globals.MainFileValidExtension)
4546
sketchDir, err := filepath.Abs(trimmedSketchName)
4647
if err != nil {
4748
feedback.Errorf(tr("Error creating sketch: %v"), err)

Diff for: commands/sketch/new.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"path/filepath"
2323

24+
"github.com/arduino/arduino-cli/arduino/globals"
2425
"github.com/arduino/arduino-cli/commands"
2526
"github.com/arduino/arduino-cli/configuration"
2627
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -40,7 +41,7 @@ func CreateSketch(sketchDir string, sketchName string) (string, error) {
4041
return "", err
4142
}
4243
baseSketchName := filepath.Base(sketchDir)
43-
sketchFile := filepath.Join(sketchDir, baseSketchName+".ino")
44+
sketchFile := filepath.Join(sketchDir, baseSketchName+globals.MainFileValidExtension)
4445
if err := ioutil.WriteFile(sketchFile, emptySketch, os.FileMode(0644)); err != nil {
4546
return "", err
4647
}

Diff for: i18n/data/en.po

+4-4
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ msgstr "Couldn't determine program size"
465465
msgid "Couldn't get current working directory: %v"
466466
msgstr "Couldn't get current working directory: %v"
467467

468-
#: cli/sketch/new.go:32
469468
#: cli/sketch/new.go:33
469+
#: cli/sketch/new.go:34
470470
msgid "Create a new Sketch"
471471
msgstr "Create a new Sketch"
472472

@@ -655,8 +655,8 @@ msgstr "Error creating output dir"
655655
msgid "Error creating sketch archive"
656656
msgstr "Error creating sketch archive"
657657

658-
#: cli/sketch/new.go:47
659-
#: cli/sketch/new.go:52
658+
#: cli/sketch/new.go:48
659+
#: cli/sketch/new.go:53
660660
msgid "Error creating sketch: %v"
661661
msgstr "Error creating sketch: %v"
662662

@@ -1978,7 +1978,7 @@ msgstr "Size (bytes):"
19781978
msgid "Sketch cannot be located in build path. Please specify a different build path"
19791979
msgstr "Sketch cannot be located in build path. Please specify a different build path"
19801980

1981-
#: cli/sketch/new.go:56
1981+
#: cli/sketch/new.go:57
19821982
msgid "Sketch created in: %s"
19831983
msgstr "Sketch created in: %s"
19841984

0 commit comments

Comments
 (0)