code.cloudfoundry.org/cli@v7.1.0+incompatible/command/v7/staging_security_groups_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/util/ui"
     5  )
     6  
     7  type StagingSecurityGroupsCommand struct {
     8  	BaseCommand
     9  
    10  	usage           interface{} `usage:"CF_NAME staging-security-groups"`
    11  	relatedCommands interface{} `related_commands:"bind-staging-security-group, security-group, unbind-staging-security-group"`
    12  }
    13  
    14  func (cmd StagingSecurityGroupsCommand) Execute(args []string) error {
    15  	err := cmd.SharedActor.CheckTarget(false, false)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	user, err := cmd.Config.CurrentUser()
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	cmd.UI.DisplayTextWithFlavor("Getting global staging security groups as {{.Username}}...", map[string]interface{}{
    26  		"Username": user.Name,
    27  	})
    28  	cmd.UI.DisplayNewline()
    29  
    30  	stagingSecurityGroups, warnings, err := cmd.Actor.GetGlobalStagingSecurityGroups()
    31  	cmd.UI.DisplayWarnings(warnings)
    32  	if err != nil {
    33  		return err
    34  	}
    35  
    36  	if len(stagingSecurityGroups) == 0 {
    37  		cmd.UI.DisplayText("No global staging security groups found.")
    38  		return nil
    39  	}
    40  
    41  	table := [][]string{{
    42  		cmd.UI.TranslateText("name"),
    43  	}}
    44  	for _, stagingSecurityGroup := range stagingSecurityGroups {
    45  		table = append(table, []string{
    46  			cmd.UI.TranslateText(stagingSecurityGroup.Name),
    47  		})
    48  	}
    49  	cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding)
    50  
    51  	return nil
    52  }