forked from plouc/go-gitlab-client
/
rm_alias.go
40 lines (32 loc) · 834 Bytes
/
rm_alias.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
package cmd
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
func init() {
rmCmd.AddCommand(rmAliasCmd)
}
var rmAliasCmd = &cobra.Command{
Use: "alias [alias] [resource type]",
Aliases: []string{"a"},
Short: "Remove resource alias",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return fmt.Errorf("you must specify an alias and a resource type")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
alias := args[0]
resourceType := args[1]
color.Yellow("Removing %s alias %s…", resourceType, alias)
_, a := config.findAlias(alias, resourceType)
if a == nil {
color.Red("✘ No %s alias found for %s", resourceType, alias)
return
}
config.Write(configFile)
color.Green("✔ Alias %s was successfully removed", alias)
},
}