generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
logout.go
58 lines (49 loc) · 1.44 KB
/
logout.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
52
53
54
55
56
57
58
// Package logout is for the logout command
package logout
import (
"strings"
"github.com/spf13/cobra"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)
type LogoutOptions struct {
auth Auth
}
type Auth interface {
Logout() error
}
func NewCmdLogout(auth Auth) *cobra.Command {
opts := LogoutOptions{
auth: auth,
}
cmd := &cobra.Command{
Annotations: map[string]string{"housekeeping": ""},
Use: "logout",
DisableFlagsInUseLine: true,
Short: "Log out of brev",
Long: "Log out of brev by deleting the credential file",
Example: "brev logout",
Args: cobra.NoArgs,
// ValidArgsFunction: util.ResourceNameCompletionFunc(f, "pod"),
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(opts.Complete(cmd, args))
cmdutil.CheckErr(opts.RunLogout())
},
}
return cmd
}
func (o *LogoutOptions) Complete(_ *cobra.Command, _ []string) error {
// func (o *LogoutOptions) Complete(cmd *cobra.Command, args []string) error {
// return fmt.Errorf("not implemented")
return nil
}
func (o *LogoutOptions) RunLogout() error {
// func (o *LogoutOptions) RunLogout(cmd *cobra.Command, args []string) error {
err := o.auth.Logout()
if err != nil {
if !strings.Contains(err.Error(), ".brev/credentials.json: no such file or directory") {
return breverrors.WrapAndTrace(err)
}
}
return nil
}