Skip to content

Commit aa5bb45

Browse files
committed
Moved legacy function unquote from arduino-cli here
1 parent afb724f commit aa5bb45

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

main.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ import (
4040
"runtime"
4141
"runtime/pprof"
4242
"runtime/trace"
43+
"strconv"
4344
"strings"
4445
"syscall"
4546

4647
"github.com/arduino/arduino-cli/arduino/cores"
4748
"github.com/arduino/arduino-cli/legacy/builder"
48-
"github.com/arduino/arduino-cli/legacy/builder/gohasissues"
4949
jsonrpc "github.com/arduino/arduino-cli/legacy/builder/grpc"
5050
"github.com/arduino/arduino-cli/legacy/builder/i18n"
5151
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -286,7 +286,7 @@ func main() {
286286
}
287287

288288
// FLAG_FQBN
289-
if fqbnIn, err := gohasissues.Unquote(*fqbnFlag); err != nil {
289+
if fqbnIn, err := unquote(*fqbnFlag); err != nil {
290290
printCompleteError(err)
291291
} else if fqbnIn != "" {
292292
if fqbn, err := cores.ParseFQBN(fqbnIn); err != nil {
@@ -301,7 +301,7 @@ func main() {
301301

302302
// FLAG_BUILD_PATH
303303
if *buildPathFlag != "" {
304-
buildPathUnquoted, err := gohasissues.Unquote(*buildPathFlag)
304+
buildPathUnquoted, err := unquote(*buildPathFlag)
305305
if err != nil {
306306
printCompleteError(err)
307307
}
@@ -320,7 +320,7 @@ func main() {
320320

321321
// FLAG_BUILD_CACHE
322322
if *buildCachePathFlag != "" {
323-
buildCachePathUnquoted, err := gohasissues.Unquote(*buildCachePathFlag)
323+
buildCachePathUnquoted, err := unquote(*buildCachePathFlag)
324324
if err != nil {
325325
printCompleteError(err)
326326
}
@@ -339,7 +339,7 @@ func main() {
339339
}
340340

341341
if flag.NArg() > 0 {
342-
sketchLocationUnquoted, err := gohasissues.Unquote(flag.Arg(0))
342+
sketchLocationUnquoted, err := unquote(flag.Arg(0))
343343
if err != nil {
344344
printCompleteError(err)
345345
}
@@ -424,7 +424,7 @@ func toExitCode(err error) int {
424424
func toSliceOfUnquoted(value []string) ([]string, error) {
425425
var values []string
426426
for _, v := range value {
427-
v, err := gohasissues.Unquote(v)
427+
v, err := unquote(v)
428428
if err != nil {
429429
return nil, err
430430
}
@@ -433,6 +433,22 @@ func toSliceOfUnquoted(value []string) ([]string, error) {
433433
return values, nil
434434
}
435435

436+
func unquote(s string) (string, error) {
437+
if stringStartsEndsWith(s, "'") {
438+
s = s[1 : len(s)-1]
439+
}
440+
441+
if !stringStartsEndsWith(s, "\"") {
442+
return s, nil
443+
}
444+
445+
return strconv.Unquote(s)
446+
}
447+
448+
func stringStartsEndsWith(s string, c string) bool {
449+
return strings.HasPrefix(s, c) && strings.HasSuffix(s, c)
450+
}
451+
436452
func printCompleteError(err error) {
437453
err = i18n.WrapError(err)
438454
fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack())

0 commit comments

Comments
 (0)