github.com/chenbh/concourse/v6@v6.4.2/fly/commands/destroy_team.go (about) 1 package commands 2 3 import ( 4 "errors" 5 "fmt" 6 "os" 7 8 "github.com/chenbh/concourse/v6/fly/commands/internal/flaghelpers" 9 "github.com/chenbh/concourse/v6/fly/rc" 10 "github.com/chenbh/concourse/v6/fly/ui" 11 "github.com/chenbh/concourse/v6/go-concourse/concourse" 12 "github.com/vito/go-interact/interact" 13 ) 14 15 type DestroyTeamCommand struct { 16 Team flaghelpers.TeamFlag `short:"n" long:"team-name" required:"true" description:"The team to delete"` 17 SkipInteractive bool `long:"non-interactive" description:"Force apply configuration"` 18 } 19 20 func (command *DestroyTeamCommand) Execute([]string) error { 21 target, err := rc.LoadTarget(Fly.Target, Fly.Verbose) 22 if err != nil { 23 return err 24 } 25 26 err = target.Validate() 27 if err != nil { 28 return err 29 } 30 31 teamName := command.Team.Name() 32 fmt.Printf("!!! this will remove all data for team `%s`\n\n", teamName) 33 34 if !command.SkipInteractive { 35 var confirm string 36 err = interact.NewInteraction("please type the team name to confirm").Resolve(interact.Required(&confirm)) 37 if err != nil { 38 return err 39 } 40 41 if confirm != teamName { 42 return errors.New("incorrect team name; bailing out") 43 } 44 } 45 46 err = target.Team().DestroyTeam(teamName) 47 switch err { 48 case nil: 49 fmt.Println() 50 fmt.Printf("`%s` deleted\n", teamName) 51 return nil 52 case concourse.ErrDestroyRefused: 53 fmt.Println() 54 fmt.Println(ui.WarningColor("could not destroy `%s`", teamName)) 55 fmt.Println() 56 fmt.Println("either your team is not an admin or it is the last admin team") 57 os.Exit(1) 58 default: 59 return err 60 } 61 62 panic("unreachable") 63 }