forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
destroy_team.go
59 lines (49 loc) · 1.27 KB
/
destroy_team.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
59
package commands
import (
"errors"
"fmt"
"os"
"github.com/concourse/fly/rc"
"github.com/concourse/fly/ui"
"github.com/concourse/go-concourse/concourse"
"github.com/vito/go-interact/interact"
)
type DestroyTeamCommand struct {
TeamName string `short:"n" long:"team-name" required:"true" description:"The team to delete"`
}
func (command *DestroyTeamCommand) Execute([]string) error {
target, err := rc.LoadTarget(Fly.Target)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
teamName := command.TeamName
fmt.Printf("!!! this will remove all data for team `%s`\n\n", teamName)
var confirm string
err = interact.NewInteraction("please type the team name to confirm").Resolve(interact.Required(&confirm))
if err != nil {
return err
}
if confirm != teamName {
return errors.New("incorrect team name; bailing out")
}
err = target.Team().DestroyTeam(teamName)
switch err {
case nil:
fmt.Println()
fmt.Printf("`%s` deleted\n", teamName)
return nil
case concourse.ErrDestroyRefused:
fmt.Println()
fmt.Printf(ui.WarningColor("could not destroy `%s`\n", teamName))
fmt.Println()
fmt.Println("either your team is not an admin or it is the last admin team")
os.Exit(1)
default:
return err
}
panic("unreachable")
}