-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
45 lines (37 loc) · 991 Bytes
/
delete.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
package cmd
import (
"github.com/ohsawa0515/akm/credentials"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func NewCmdDelete() *cobra.Command {
cmd := &cobra.Command{
Use: "delete PROFILE",
Aliases: []string{"del", "d"},
Short: "Delete profile from AWS credentials file.",
Long: `Delete profile from AWS credentials file.
When the profile is deleted, the credentials file is **overwritten**.`,
Example: `akm delete foo`,
Args: cobra.MinimumNArgs(1),
RunE: deleteAction,
}
return cmd
}
func deleteAction(cmd *cobra.Command, args []string) error {
ac, err := credentials.NewAwsCredentials()
if err != nil {
return err
}
if len(args) == 0 {
return errors.Errorf("Specify a profile")
}
profile := args[0]
if _, ok := ac[profile]; !ok {
return errors.Errorf("profile: %s doesn't exist", profile)
}
// Delete profile from credentials file
if err := ac[profile].DeleteProfilePrompt(profile); err != nil {
return err
}
return nil
}