forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logout.go
41 lines (31 loc) · 780 Bytes
/
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
package commands
import (
"errors"
"fmt"
"github.com/concourse/fly/rc"
)
type LogoutCommand struct {
All bool `short:"a" long:"all" description:"Logout of all targets"`
}
func (command *LogoutCommand) Execute(args []string) error {
if Fly.Target != "" && !command.All {
if err := rc.DeleteTarget(Fly.Target); err != nil {
return err
}
fmt.Println("logged out of target: " + Fly.Target)
} else if Fly.Target == "" && command.All {
flyYAML, err := rc.LoadTargets()
if err != nil {
return err
}
for targetName := range flyYAML.Targets {
if err := rc.DeleteTarget(targetName); err != nil {
return err
}
}
fmt.Println("logged out of all targets")
} else {
return errors.New("must specify either --target or --all")
}
return nil
}