Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3211746

Browse files
committedJul 22, 2019
consolidate argument parsing
1 parent 5a4f31d commit 3211746

File tree

14 files changed

+327
-241
lines changed

14 files changed

+327
-241
lines changed
 

‎arduino/libraries/librariesindex/reference.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
package librariesindex
1919

2020
import (
21-
"fmt"
22-
"strings"
23-
2421
semver "go.bug.st/relaxed-semver"
2522
)
2623

@@ -36,23 +33,3 @@ func (r *Reference) String() string {
3633
}
3734
return r.Name + "@" + r.Version.String()
3835
}
39-
40-
// ParseArgs parses a sequence of "item@version" tokens and returns a Name-Version slice.
41-
//
42-
// If version is not present it is assumed as "latest" version.
43-
func ParseArgs(args []string) ([]*Reference, error) {
44-
res := []*Reference{}
45-
for _, item := range args {
46-
tokens := strings.SplitN(item, "@", 2)
47-
if len(tokens) == 2 {
48-
version, err := semver.Parse(tokens[1])
49-
if err != nil {
50-
return nil, fmt.Errorf("invalid version %s: %s", version, err)
51-
}
52-
res = append(res, &Reference{Name: tokens[0], Version: version})
53-
} else {
54-
res = append(res, &Reference{Name: tokens[0]})
55-
}
56-
}
57-
return res, nil
58-
}

‎cli/core/args.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

‎cli/core/args_test.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

‎cli/core/download.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
5050
instance := instance.CreateInstance()
5151
logrus.Info("Executing `arduino core download`")
5252

53-
platformsRefs := parsePlatformReferenceArgs(args)
53+
platformsRefs, err := globals.ParseReferenceArgs(args, true)
54+
if err != nil {
55+
formatter.PrintError(err, "Invalid argument passed")
56+
os.Exit(errorcodes.ErrBadArgument)
57+
}
58+
5459
for i, platformRef := range platformsRefs {
5560
platformDownloadreq := &rpc.PlatformDownloadReq{
5661
Instance: instance,
57-
PlatformPackage: platformRef.Package,
62+
PlatformPackage: platformRef.PackageName,
5863
Architecture: platformRef.Architecture,
5964
Version: platformRef.Version,
6065
}

‎cli/core/install.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
5151
instance := instance.CreateInstance()
5252
logrus.Info("Executing `arduino core install`")
5353

54-
platformsRefs := parsePlatformReferenceArgs(args)
54+
platformsRefs, err := globals.ParseReferenceArgs(args, true)
55+
if err != nil {
56+
formatter.PrintError(err, "Invalid argument passed")
57+
os.Exit(errorcodes.ErrBadArgument)
58+
}
5559

5660
for _, platformRef := range platformsRefs {
5761
plattformInstallReq := &rpc.PlatformInstallReq{
5862
Instance: instance,
59-
PlatformPackage: platformRef.Package,
63+
PlatformPackage: platformRef.PackageName,
6064
Architecture: platformRef.Architecture,
6165
Version: platformRef.Version,
6266
}

‎cli/core/uninstall.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323

2424
"github.com/arduino/arduino-cli/cli/errorcodes"
25+
"github.com/arduino/arduino-cli/cli/globals"
2526
"github.com/arduino/arduino-cli/cli/instance"
2627
"github.com/arduino/arduino-cli/cli/output"
2728
"github.com/arduino/arduino-cli/commands/core"
@@ -46,7 +47,11 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
4647
instance := instance.CreateInstance()
4748
logrus.Info("Executing `arduino core uninstall`")
4849

49-
platformsRefs := parsePlatformReferenceArgs(args)
50+
platformsRefs, err := globals.ParseReferenceArgs(args, true)
51+
if err != nil {
52+
formatter.PrintError(err, "Invalid argument passed")
53+
os.Exit(errorcodes.ErrBadArgument)
54+
}
5055

5156
for _, platformRef := range platformsRefs {
5257
if platformRef.Version != "" {
@@ -57,7 +62,7 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
5762
for _, platformRef := range platformsRefs {
5863
_, err := core.PlatformUninstall(context.Background(), &rpc.PlatformUninstallReq{
5964
Instance: instance,
60-
PlatformPackage: platformRef.Package,
65+
PlatformPackage: platformRef.PackageName,
6166
Architecture: platformRef.Architecture,
6267
}, output.NewTaskProgressCB())
6368
if err != nil {

‎cli/core/upgrade.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
7272

7373
// proceed upgrading, if anything is upgradable
7474
exitErr := false
75-
platformsRefs := parsePlatformReferenceArgs(args)
75+
platformsRefs, err := globals.ParseReferenceArgs(args, true)
76+
if err != nil {
77+
formatter.PrintError(err, "Invalid argument passed")
78+
os.Exit(errorcodes.ErrBadArgument)
79+
}
80+
7681
for i, platformRef := range platformsRefs {
7782
if platformRef.Version != "" {
7883
formatter.PrintErrorMessage(("Invalid item " + args[i]))
@@ -82,7 +87,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
8287

8388
r := &rpc.PlatformUpgradeReq{
8489
Instance: instance,
85-
PlatformPackage: platformRef.Package,
90+
PlatformPackage: platformRef.PackageName,
8691
Architecture: platformRef.Architecture,
8792
}
8893

‎cli/globals/args.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to license@arduino.cc.
15+
16+
package globals
17+
18+
import (
19+
"fmt"
20+
"strings"
21+
)
22+
23+
// ReferenceArg represents a reference item (core or library) passed to the CLI
24+
// interface
25+
type ReferenceArg struct {
26+
PackageName string
27+
Architecture string
28+
Version string
29+
}
30+
31+
func (r *ReferenceArg) String() string {
32+
if r.Version != "" {
33+
return r.PackageName + ":" + r.Architecture + "@" + r.Version
34+
}
35+
return r.PackageName + ":" + r.Architecture
36+
}
37+
38+
// ParseReferenceArgs is a convenient wrapper that operates on a slice of strings and
39+
// calls ParseReferenceArg for each of them. It returns at the first invalid argument.
40+
func ParseReferenceArgs(args []string, parseArch bool) ([]*ReferenceArg, error) {
41+
ret := []*ReferenceArg{}
42+
for _, arg := range args {
43+
reference, err := ParseReferenceArg(arg, parseArch)
44+
if err != nil {
45+
return nil, err
46+
}
47+
ret = append(ret, reference)
48+
}
49+
return ret, nil
50+
}
51+
52+
// ParseReferenceArg parses a string and return a ReferenceArg object. If `parseArch` is passed,
53+
// the method also tries to parse the architecture bit, i.e. string must be in the form
54+
// "packager:arch@version", useful to represent a platform (or core) name.
55+
func ParseReferenceArg(arg string, parseArch bool) (*ReferenceArg, error) {
56+
ret := &ReferenceArg{}
57+
58+
toks := strings.SplitN(arg, "@", 2)
59+
ret.PackageName = toks[0]
60+
if len(toks) > 1 {
61+
ret.Version = toks[1]
62+
}
63+
64+
if parseArch {
65+
toks = strings.Split(ret.PackageName, ":")
66+
if len(toks) != 2 {
67+
return nil, fmt.Errorf("invalid item %s", arg)
68+
}
69+
ret.PackageName = toks[0]
70+
ret.Architecture = toks[1]
71+
}
72+
73+
return ret, nil
74+
}

‎cli/globals/args_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to license@arduino.cc.
16+
*/
17+
18+
package globals_test
19+
20+
import (
21+
"testing"
22+
23+
"github.com/arduino/arduino-cli/cli/globals"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
var goodCores = []struct {
28+
in string
29+
expected *globals.ReferenceArg
30+
}{
31+
{"arduino:avr", &globals.ReferenceArg{"arduino", "avr", ""}},
32+
{"arduino:avr@1.6.20", &globals.ReferenceArg{"arduino", "avr", "1.6.20"}},
33+
{"arduino:avr@", &globals.ReferenceArg{"arduino", "avr", ""}},
34+
}
35+
36+
var goodLibs = []struct {
37+
in string
38+
expected *globals.ReferenceArg
39+
}{
40+
{"mylib", &globals.ReferenceArg{"mylib", "", ""}},
41+
{"mylib@1.0", &globals.ReferenceArg{"mylib", "", "1.0"}},
42+
{"mylib@", &globals.ReferenceArg{"mylib", "", ""}},
43+
}
44+
45+
var badCores = []struct {
46+
in string
47+
expected *globals.ReferenceArg
48+
}{
49+
{"arduino:avr:avr", nil},
50+
{"arduino@1.6.20:avr", nil},
51+
{"arduino:avr:avr@1.6.20", nil},
52+
}
53+
54+
func TestParseReferenceArgCores(t *testing.T) {
55+
for _, tt := range goodCores {
56+
actual, err := globals.ParseReferenceArg(tt.in, true)
57+
assert.Nil(t, err)
58+
assert.Equal(t, tt.expected, actual)
59+
}
60+
61+
for _, tt := range badCores {
62+
actual, err := globals.ParseReferenceArg(tt.in, true)
63+
assert.NotNil(t, err)
64+
assert.Equal(t, tt.expected, actual)
65+
}
66+
67+
// library refs are not good as core's
68+
for _, tt := range goodLibs {
69+
_, err := globals.ParseReferenceArg(tt.in, true)
70+
assert.NotNil(t, err)
71+
}
72+
}
73+
74+
func TestParseReferenceArgLibs(t *testing.T) {
75+
for _, tt := range goodLibs {
76+
actual, err := globals.ParseReferenceArg(tt.in, false)
77+
assert.Nil(t, err)
78+
assert.Equal(t, tt.expected, actual)
79+
}
80+
81+
// good libs are bad when requiring Arch to be present
82+
for _, tt := range goodLibs {
83+
_, err := globals.ParseReferenceArg(tt.in, true)
84+
assert.NotNil(t, err)
85+
}
86+
}
87+
88+
func TestParseArgs(t *testing.T) {
89+
input := []string{}
90+
for _, tt := range goodCores {
91+
input = append(input, tt.in)
92+
}
93+
94+
refs, err := globals.ParseReferenceArgs(input, true)
95+
assert.Nil(t, err)
96+
assert.Equal(t, len(goodCores), len(refs))
97+
98+
for i, tt := range goodCores {
99+
assert.Equal(t, tt.expected, refs[i])
100+
}
101+
}

‎cli/globals/configs.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to license@arduino.cc.
15+
16+
package globals
17+
18+
import (
19+
"fmt"
20+
"os"
21+
22+
"github.com/arduino/arduino-cli/cli/errorcodes"
23+
"github.com/arduino/arduino-cli/common/formatter"
24+
"github.com/arduino/arduino-cli/configs"
25+
"github.com/arduino/go-paths-helper"
26+
"github.com/sirupsen/logrus"
27+
)
28+
29+
// InitConfigs initializes the configuration from the specified file.
30+
func InitConfigs() {
31+
// Start with default configuration
32+
if conf, err := configs.NewConfiguration(); err != nil {
33+
logrus.WithError(err).Error("Error creating default configuration")
34+
formatter.PrintError(err, "Error creating default configuration")
35+
os.Exit(errorcodes.ErrGeneric)
36+
} else {
37+
Config = conf
38+
}
39+
40+
// Read configuration from global config file
41+
logrus.Info("Checking for config file in: " + Config.ConfigFile.String())
42+
if Config.ConfigFile.Exist() {
43+
readConfigFrom(Config.ConfigFile)
44+
}
45+
46+
if Config.IsBundledInDesktopIDE() {
47+
logrus.Info("CLI is bundled into the IDE")
48+
err := Config.LoadFromDesktopIDEPreferences()
49+
if err != nil {
50+
logrus.WithError(err).Warn("Did not manage to get config file of IDE, using default configuration")
51+
}
52+
} else {
53+
logrus.Info("CLI is not bundled into the IDE")
54+
}
55+
56+
// Read configuration from parent folders (project config)
57+
if pwd, err := paths.Getwd(); err != nil {
58+
logrus.WithError(err).Warn("Did not manage to find current path")
59+
if path := paths.New("arduino-yaml"); path.Exist() {
60+
readConfigFrom(path)
61+
}
62+
} else {
63+
Config.Navigate(pwd)
64+
}
65+
66+
// Read configuration from old configuration file if found, but output a warning.
67+
if old := paths.New(".cli-config.yml"); old.Exist() {
68+
logrus.Errorf("Old configuration file detected: %s.", old)
69+
logrus.Info("The name of this file has been changed to `arduino-yaml`, please rename the file fix it.")
70+
formatter.PrintError(
71+
fmt.Errorf("WARNING: Old configuration file detected: %s", old),
72+
"The name of this file has been changed to `arduino-yaml`, in a future release we will not support"+
73+
"the old name `.cli-config.yml` anymore. Please rename the file to `arduino-yaml` to silence this warning.")
74+
readConfigFrom(old)
75+
}
76+
77+
// Read configuration from environment vars
78+
Config.LoadFromEnv()
79+
80+
// Read configuration from user specified file
81+
if YAMLConfigFile != "" {
82+
Config.ConfigFile = paths.New(YAMLConfigFile)
83+
readConfigFrom(Config.ConfigFile)
84+
}
85+
86+
logrus.Info("Configuration set")
87+
}
88+
89+
func readConfigFrom(path *paths.Path) {
90+
logrus.Infof("Reading configuration from %s", path)
91+
if err := Config.LoadFromYAML(path); err != nil {
92+
logrus.WithError(err).Warnf("Could not read configuration from %s", path)
93+
}
94+
}

‎cli/globals/globals.go

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to license@arduino.cc.
15+
116
package globals
217

318
import (
@@ -7,12 +22,8 @@ import (
722
"path/filepath"
823
"runtime"
924

10-
"github.com/arduino/arduino-cli/cli/errorcodes"
11-
"github.com/arduino/arduino-cli/common/formatter"
1225
"github.com/arduino/arduino-cli/configs"
1326
"github.com/arduino/arduino-cli/version"
14-
"github.com/arduino/go-paths-helper"
15-
"github.com/sirupsen/logrus"
1627
)
1728

1829
var (
@@ -36,70 +47,3 @@ func getHTTPClientHeader() http.Header {
3647
downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}}
3748
return downloaderHeaders
3849
}
39-
40-
// InitConfigs initializes the configuration from the specified file.
41-
func InitConfigs() {
42-
// Start with default configuration
43-
if conf, err := configs.NewConfiguration(); err != nil {
44-
logrus.WithError(err).Error("Error creating default configuration")
45-
formatter.PrintError(err, "Error creating default configuration")
46-
os.Exit(errorcodes.ErrGeneric)
47-
} else {
48-
Config = conf
49-
}
50-
51-
// Read configuration from global config file
52-
logrus.Info("Checking for config file in: " + Config.ConfigFile.String())
53-
if Config.ConfigFile.Exist() {
54-
readConfigFrom(Config.ConfigFile)
55-
}
56-
57-
if Config.IsBundledInDesktopIDE() {
58-
logrus.Info("CLI is bundled into the IDE")
59-
err := Config.LoadFromDesktopIDEPreferences()
60-
if err != nil {
61-
logrus.WithError(err).Warn("Did not manage to get config file of IDE, using default configuration")
62-
}
63-
} else {
64-
logrus.Info("CLI is not bundled into the IDE")
65-
}
66-
67-
// Read configuration from parent folders (project config)
68-
if pwd, err := paths.Getwd(); err != nil {
69-
logrus.WithError(err).Warn("Did not manage to find current path")
70-
if path := paths.New("arduino-yaml"); path.Exist() {
71-
readConfigFrom(path)
72-
}
73-
} else {
74-
Config.Navigate(pwd)
75-
}
76-
77-
// Read configuration from old configuration file if found, but output a warning.
78-
if old := paths.New(".cli-config.yml"); old.Exist() {
79-
logrus.Errorf("Old configuration file detected: %s.", old)
80-
logrus.Info("The name of this file has been changed to `arduino-yaml`, please rename the file fix it.")
81-
formatter.PrintError(
82-
fmt.Errorf("WARNING: Old configuration file detected: %s", old),
83-
"The name of this file has been changed to `arduino-yaml`, in a future release we will not support"+
84-
"the old name `.cli-config.yml` anymore. Please rename the file to `arduino-yaml` to silence this warning.")
85-
readConfigFrom(old)
86-
}
87-
88-
// Read configuration from environment vars
89-
Config.LoadFromEnv()
90-
91-
// Read configuration from user specified file
92-
if YAMLConfigFile != "" {
93-
Config.ConfigFile = paths.New(YAMLConfigFile)
94-
readConfigFrom(Config.ConfigFile)
95-
}
96-
97-
logrus.Info("Configuration set")
98-
}
99-
100-
func readConfigFrom(path *paths.Path) {
101-
logrus.Infof("Reading configuration from %s", path)
102-
if err := Config.LoadFromYAML(path); err != nil {
103-
logrus.WithError(err).Warnf("Could not read configuration from %s", path)
104-
}
105-
}

‎cli/lib/download.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"os"
2323

24-
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
2524
"github.com/arduino/arduino-cli/cli/errorcodes"
2625
"github.com/arduino/arduino-cli/cli/globals"
2726
"github.com/arduino/arduino-cli/cli/instance"
@@ -48,16 +47,17 @@ func initDownloadCommand() *cobra.Command {
4847

4948
func runDownloadCommand(cmd *cobra.Command, args []string) {
5049
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
51-
pairs, err := librariesindex.ParseArgs(args)
50+
refs, err := globals.ParseReferenceArgs(args, false)
5251
if err != nil {
53-
formatter.PrintError(err, "Arguments error")
52+
formatter.PrintError(err, "Invalid argument passed")
5453
os.Exit(errorcodes.ErrBadArgument)
5554
}
56-
for _, library := range pairs {
55+
56+
for _, library := range refs {
5757
libraryDownloadReq := &rpc.LibraryDownloadReq{
5858
Instance: instance,
59-
Name: library.Name,
60-
Version: library.Version.String(),
59+
Name: library.PackageName,
60+
Version: library.Version,
6161
}
6262
_, err := lib.LibraryDownload(context.Background(), libraryDownloadReq, output.ProgressBar(),
6363
globals.HTTPClientHeader)

‎cli/lib/install.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"os"
2323

24-
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
2524
"github.com/arduino/arduino-cli/cli/errorcodes"
2625
"github.com/arduino/arduino-cli/cli/globals"
2726
"github.com/arduino/arduino-cli/cli/instance"
@@ -48,16 +47,17 @@ func initInstallCommand() *cobra.Command {
4847

4948
func runInstallCommand(cmd *cobra.Command, args []string) {
5049
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
51-
refs, err := librariesindex.ParseArgs(args)
50+
refs, err := globals.ParseReferenceArgs(args, false)
5251
if err != nil {
5352
formatter.PrintError(err, "Arguments error")
5453
os.Exit(errorcodes.ErrBadArgument)
5554
}
55+
5656
for _, library := range refs {
5757
libraryInstallReq := &rpc.LibraryInstallReq{
5858
Instance: instance,
59-
Name: library.Name,
60-
Version: library.Version.String(),
59+
Name: library.PackageName,
60+
Version: library.Version,
6161
}
6262
err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(),
6363
output.TaskProgress(), globals.HTTPClientHeader)

‎cli/lib/uninstall.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"context"
2222
"os"
2323

24-
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
2524
"github.com/arduino/arduino-cli/cli/errorcodes"
25+
"github.com/arduino/arduino-cli/cli/globals"
2626
"github.com/arduino/arduino-cli/cli/instance"
2727
"github.com/arduino/arduino-cli/cli/output"
2828
"github.com/arduino/arduino-cli/commands/lib"
@@ -48,17 +48,17 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
4848
logrus.Info("Executing `arduino lib uninstall`")
4949

5050
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
51-
libRefs, err := librariesindex.ParseArgs(args)
51+
refs, err := globals.ParseReferenceArgs(args, false)
5252
if err != nil {
53-
formatter.PrintError(err, "Arguments error")
53+
formatter.PrintError(err, "Invalid argument passed")
5454
os.Exit(errorcodes.ErrBadArgument)
5555
}
5656

57-
for _, library := range libRefs {
57+
for _, library := range refs {
5858
err := lib.LibraryUninstall(context.Background(), &rpc.LibraryUninstallReq{
5959
Instance: instance,
60-
Name: library.Name,
61-
Version: library.Version.String(),
60+
Name: library.PackageName,
61+
Version: library.Version,
6262
}, output.TaskProgress())
6363
if err != nil {
6464
formatter.PrintError(err, "Error uninstalling "+library.String())

0 commit comments

Comments
 (0)
Please sign in to comment.