@@ -18,6 +18,10 @@ package arguments
18
18
import (
19
19
"fmt"
20
20
"strings"
21
+
22
+ "github.com/arduino/arduino-cli/arduino/cores"
23
+ "github.com/arduino/arduino-cli/commands"
24
+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
21
25
)
22
26
23
27
// Reference represents a reference item (core or library) passed to the CLI
@@ -37,10 +41,10 @@ func (r *Reference) String() string {
37
41
38
42
// ParseReferences is a convenient wrapper that operates on a slice of strings and
39
43
// calls ParseReference for each of them. It returns at the first invalid argument.
40
- func ParseReferences (args []string ) ([]* Reference , error ) {
44
+ func ParseReferences (args []string , inst * rpc. Instance ) ([]* Reference , error ) {
41
45
ret := []* Reference {}
42
46
for _ , arg := range args {
43
- reference , err := ParseReference (arg )
47
+ reference , err := ParseReference (arg , inst )
44
48
if err != nil {
45
49
return nil , err
46
50
}
@@ -52,7 +56,7 @@ func ParseReferences(args []string) ([]*Reference, error) {
52
56
// ParseReference parses a string and returns a Reference object. If `parseArch` is passed,
53
57
// the method also tries to parse the architecture bit, i.e. string must be in the form
54
58
// "packager:arch@version", useful to represent a platform (or core) name.
55
- func ParseReference (arg string ) (* Reference , error ) {
59
+ func ParseReference (arg string , inst * rpc. Instance ) (* Reference , error ) {
56
60
ret := & Reference {}
57
61
if arg == "" {
58
62
return nil , fmt .Errorf (tr ("invalid empty core argument" ))
@@ -77,10 +81,31 @@ func ParseReference(arg string) (*Reference, error) {
77
81
return nil , fmt .Errorf (tr ("invalid empty core name '%s'" ), arg )
78
82
}
79
83
ret .PackageName = toks [0 ]
84
+
85
+ // try to search in the packages, this way ParseReference can be case insensitive
86
+ // note that if the search fail for some reason the ret.Packagename does not get overwritten
87
+ var targetPackage * cores.Package
88
+ if inst != nil { // do not perform the search if the instance is not defined
89
+ pm := commands .GetPackageManager (inst .Id )
90
+ for _ , targetPackage = range pm .Packages {
91
+ if targetPackage .Name == strings .ToLower (ret .PackageName ) {
92
+ ret .PackageName = targetPackage .Name
93
+ break
94
+ }
95
+ }
96
+ }
80
97
if toks [1 ] == "" {
81
98
return nil , fmt .Errorf (tr ("invalid empty core architecture '%s'" ), arg )
82
99
}
83
100
ret .Architecture = toks [1 ]
84
-
101
+ // we do the same for architecture
102
+ if inst != nil { // do not perform the search if the instance is not defined
103
+ for _ , platform := range targetPackage .Platforms {
104
+ if platform .Architecture == strings .ToLower (ret .Architecture ) {
105
+ ret .Architecture = platform .Architecture
106
+ break
107
+ }
108
+ }
109
+ }
85
110
return ret , nil
86
111
}
0 commit comments