-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.go
51 lines (38 loc) · 1.11 KB
/
remove.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
47
48
49
50
51
package profile
import (
"errors"
"bunnyshell.com/cli/pkg/config"
"bunnyshell.com/cli/pkg/lib"
"github.com/spf13/cobra"
)
func init() {
options := config.GetOptions()
settings := config.GetSettings()
command := &cobra.Command{
Use: "remove",
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
if errors.Is(config.MainManager.Error, config.ErrConfigLoad) {
return config.MainManager.Error
}
if err := removeProfile(&settings.Profile); err != nil {
return lib.FormatCommandError(cmd, err)
}
if err := config.MainManager.Save(); err != nil {
return lib.FormatCommandError(cmd, err)
}
return lib.FormatCommandData(cmd, map[string]interface{}{
"message": "Profile removed",
"data": settings.Profile.Name,
})
},
}
flags := command.Flags()
profileNameFlag := options.ProfileName.CloneMainFlag()
flags.AddFlag(profileNameFlag)
_ = command.MarkFlagRequired(profileNameFlag.Name)
mainCmd.AddCommand(command)
}
func removeProfile(profile *config.Profile) error {
return config.MainManager.RemoveProfile(profile.Name)
}