-
Notifications
You must be signed in to change notification settings - Fork 45
/
uninstall.go
42 lines (37 loc) · 1.24 KB
/
uninstall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cmd
import (
"os"
"github.com/devops-works/binenv/internal/app"
"github.com/spf13/cobra"
)
// localCmd represents the local command
func uninstallCmd(a *app.App) *cobra.Command {
cmd := &cobra.Command{
Use: "uninstall <distribution> [<version> [<distribution> <version>]]",
Short: "Uninstall a distribution or a specific version for the distribution",
Long: `When a version is not specified, only a single distribution is accepted.
In this case, all versions for the specified distribution will be removed (a confirmation is asked).
Multiple distribution / version pairs can be specified.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
os.Exit(1)
}
a.Uninstall(args...)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
switch len(args) % 2 {
case 0:
// complete application name
return a.GetPackagesListWithPrefix(toComplete), cobra.ShellCompDirectiveNoFileComp
case 1:
// complete application version
return a.GetInstalledVersionsFor(args[len(args)-1]), cobra.ShellCompDirectiveNoFileComp
default:
// huh ?
return nil, cobra.ShellCompDirectiveNoFileComp
}
},
}
return cmd
}