-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm.go
46 lines (37 loc) · 970 Bytes
/
rm.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
43
44
45
46
package main
import (
"fmt"
"github.com/99designs/keyring"
"gopkg.in/alecthomas/kingpin.v2"
)
type RemoveCommandInput struct {
Profile string
Keyring keyring.Keyring
}
func ConfigureRemoveCommand(app *kingpin.Application) {
input := RemoveCommandInput{}
cmd := app.Command("remove", "Removes credentials")
cmd.Alias("rm")
cmd.Arg("profile", "Name of the profile").
Required().
StringVar(&input.Profile)
cmd.Action(func(c *kingpin.ParseContext) error {
input.Keyring = keyringImpl
RemoveCommand(app, input)
return nil
})
}
func RemoveCommand(app *kingpin.Application, input RemoveCommandInput) {
r, err := TerminalPrompt(fmt.Sprintf("Delete credentials for profile %q? (Y|n)", input.Profile))
if err != nil {
app.Fatalf(err.Error())
return
} else if r == "N" || r == "n" {
return
}
if err := input.Keyring.Remove(input.Profile); err != nil {
app.Fatalf(err.Error())
return
}
fmt.Printf("Deleted credentials.\n")
}