func SelectCreateRole(c context.Context, client *api.Client, orgID *identity.ID, name string) (*api.TeamResult, string, bool, error) {

	teams, err := client.Teams.List(c, orgID, "", primitive.MachineTeam)
	if err != nil {
		return nil, "", false, err
	}

	label := "Select Machine Role"
	addLabel := "Create a new role"
	var idx int
	if name == "" {
		idx, name, err = SelectTeamPrompt(teams, label, addLabel)
		if err != nil {
			return nil, "", false, err
		}
	} else {
		found := false
		for i, t := range teams {
			if t.Body.Name == name {
				found = true
				idx = i
				break
			}
		}

		if !found {
			fmt.Println(promptui.FailedValue("Machine Role", name))
			return nil, "", false, errs.NewExitError("Role not found")
		}
		fmt.Println(promptui.SuccessfulValue("Machine Role", name))
	}

	if idx == promptui.SelectedAdd {
		return nil, name, true, nil
	}

	return &teams[idx], name, false, nil
}
// SelectCreateRole prompts the user to select a machine team from a list of
// teams for the given org.
//
// The user may select to create a new team, or they may may preselect a team via
// a non-empty name parameter.
//
// It returns the object of the selected team, the name of the selected team,
// and a boolean indicating if a new team should be created.
SelectCreateRole prompts the user to select a machine team from a list of
teams for the given org.

The user may select to create a new team, or they may may preselect a team via
a non-empty name parameter.

It returns the object of the selected team, the name of the selected team,
and a boolean indicating if a new team should be created.
// SelectCreateRole prompts the user to select a machine team from a list of // teams for the given org . // // The user may select to create a new team or they may may preselect a team via // a non - empty name parameter . // // It returns the object of the selected team the name of the selected team // and a boolean indicating if a new team should be created .
func SelectCreateRole(c context.Context, client *api.Client, orgID *identity.ID, name string) (*api.TeamResult, string, bool, error) {
	teams, err := client.Teams.List(c, orgID, "", primitive.MachineTeam)
	if err != nil {
		return nil, "", false, err
	}
	label := "Select Machine Role"
	addLabel := "Create a new role"
	var idx int
	if name == "" {
		idx, name, err = SelectTeamPrompt(teams, label, addLabel)
		if err != nil {
			return nil, "", false, err
		}
	} else {
		found := false
		for i, t := range teams {
			if t.Body.Name == name {
				found = true
				idx = i
				break
			}
		}
		if !found {
			fmt.Println(promptui.FailedValue("Machine Role", name))
			return nil, "", false, errs.NewExitError("Role not found")
		}
		fmt.Println(promptui.SuccessfulValue("Machine Role", name))
	}
	if idx == promptui.SelectedAdd {
		return nil, name, true, nil
	}
	return &teams[idx], name, false, nil
}
func SelectCreateRole ( c context . Context , client * api . Client , orgID * identity . ID , name string ) ( * api . TeamResult , string , bool , error ) { teams , err := client . Teams . List ( c , orgID , " " , primitive . MachineTeam ) if err != nil { return nil , " " , false , err } label := " " addLabel := " " var idx int if name == " " { idx , name , err = SelectTeamPrompt ( teams , label , addLabel ) if err != nil { return nil , " " , false , err } } else { found := false for i , t := range teams { if t . Body . Name == name { found = true idx = i break } } if ! found { fmt . Println ( promptui . FailedValue ( " " , name ) ) return nil , " " , false , errs . NewExitError ( " " ) } fmt . Println ( promptui . SuccessfulValue ( " " , name ) ) } if idx == promptui . SelectedAdd { return nil , name , true , nil } return & teams [ idx ] , name , false , nil }
SelectCreateRole prompts the user to select a machine team from a list of
teams for the given org.
SelectCreateRole prompts the user to select a machine team from a list of teams for the given org .