Skip to content

Commit 5db5f48

Browse files
committed
add completion for core uninstall
maybe could be done better (filter and remove the manually installed ones)
1 parent bb3eb6f commit 5db5f48

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

cli/arguments/completion.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/arduino/arduino-cli/cli/instance"
88
"github.com/arduino/arduino-cli/commands"
99
"github.com/arduino/arduino-cli/commands/board"
10+
"github.com/arduino/arduino-cli/commands/core"
1011
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
1112
)
1213

@@ -88,3 +89,21 @@ func GetInstalledProgrammers(toComplete string) []string {
8889
}
8990
return res
9091
}
92+
93+
// GetUninstallableCores is an helper function useful to autocomplete.
94+
// It returns a list of cores which can be uninstalled
95+
func GetUninstallableCores(toComplete string) []string {
96+
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
97+
98+
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
99+
Instance: inst,
100+
UpdatableOnly: false,
101+
All: false,
102+
})
103+
var res []string
104+
// transform the data structure for the completion
105+
for _, i := range platforms {
106+
res = append(res, i.GetId())
107+
}
108+
return res
109+
}

cli/core/uninstall.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func initUninstallCommand() *cobra.Command {
3939
Example: " " + os.Args[0] + " core uninstall arduino:samd\n",
4040
Args: cobra.MinimumNArgs(1),
4141
Run: runUninstallCommand,
42+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
43+
return arguments.GetUninstallableCores(toComplete), cobra.ShellCompDirectiveDefault
44+
},
4245
}
4346
}
4447

i18n/data/en.po

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ msgstr "Error during build: %v"
729729
msgid "Error during install: %v"
730730
msgstr "Error during install: %v"
731731

732-
#: cli/core/uninstall.go:68
732+
#: cli/core/uninstall.go:71
733733
msgid "Error during uninstall: %v"
734734
msgstr "Error during uninstall: %v"
735735

@@ -1218,7 +1218,7 @@ msgstr "Invalid additional URL: %v"
12181218

12191219
#: cli/core/download.go:55
12201220
#: cli/core/install.go:92
1221-
#: cli/core/uninstall.go:51
1221+
#: cli/core/uninstall.go:54
12221222
#: cli/core/upgrade.go:81
12231223
#: cli/lib/download.go:50
12241224
#: cli/lib/uninstall.go:51
@@ -1266,7 +1266,7 @@ msgstr "Invalid output format: %s"
12661266
msgid "Invalid package index in %s"
12671267
msgstr "Invalid package index in %s"
12681268

1269-
#: cli/core/uninstall.go:57
1269+
#: cli/core/uninstall.go:60
12701270
msgid "Invalid parameter %s: version not allowed"
12711271
msgstr "Invalid parameter %s: version not allowed"
12721272

i18n/rice-box.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)