本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/terminal.NewTable函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTable函數的具體用法?Golang NewTable怎麽用?Golang NewTable使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTable函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (cmd ShowSecurityGroup) Run(context *cli.Context) {
name := context.Args()[0]
cmd.ui.Say("Getting info for security group '%s' as '%s'", name, cmd.configRepo.Username())
securityGroup, err := cmd.securityGroupRepo.Read(name)
if err != nil {
cmd.ui.Failed(err.Error())
}
jsonEncodedBytes, encodingErr := json.MarshalIndent(securityGroup.Rules, "\t", "\t")
if encodingErr != nil {
cmd.ui.Failed(encodingErr.Error())
}
cmd.ui.Ok()
table := terminal.NewTable(cmd.ui, []string{"", ""})
table.Add("Name", securityGroup.Name)
table.Add("Rules", "")
table.Print()
cmd.ui.Say("\t" + string(jsonEncodedBytes))
cmd.ui.Say("")
if len(securityGroup.Spaces) > 0 {
table = terminal.NewTable(cmd.ui, []string{"", "Organization", "Space"})
for index, space := range securityGroup.Spaces {
table.Add(fmt.Sprintf("#%d", index), space.Organization.Name, space.Name)
}
table.Print()
} else {
cmd.ui.Say("No spaces assigned")
}
}
示例2: Execute
func (cmd *Plugins) Execute(c flags.FlagContext) {
var version string
cmd.ui.Say(T("Listing Installed Plugins..."))
plugins := cmd.config.Plugins()
var table terminal.Table
if c.Bool("checksum") {
cmd.ui.Say(T("Computing sha1 for installed plugins, this may take a while ..."))
table = terminal.NewTable(cmd.ui, []string{T("Plugin Name"), T("Version"), T("Command Name"), "sha1", T("Command Help")})
} else {
table = terminal.NewTable(cmd.ui, []string{T("Plugin Name"), T("Version"), T("Command Name"), T("Command Help")})
}
for pluginName, metadata := range plugins {
if metadata.Version.Major == 0 && metadata.Version.Minor == 0 && metadata.Version.Build == 0 {
version = "N/A"
} else {
version = fmt.Sprintf("%d.%d.%d", metadata.Version.Major, metadata.Version.Minor, metadata.Version.Build)
}
for _, command := range metadata.Commands {
args := []string{pluginName, version}
if command.Alias != "" {
args = append(args, command.Name+", "+command.Alias)
} else {
args = append(args, command.Name)
}
if c.Bool("checksum") {
checksum := utils.NewSha1Checksum(metadata.Location)
sha1, err := checksum.ComputeFileSha1()
if err != nil {
args = append(args, "n/a")
} else {
args = append(args, fmt.Sprintf("%x", sha1))
}
}
args = append(args, command.HelpText)
table.Add(args...)
}
}
cmd.ui.Ok()
cmd.ui.Say("")
table.Print()
}
示例3: Run
func (cmd SecurityGroups) Run(context *cli.Context) {
cmd.ui.Say(T("Getting security groups as {{.username}}",
map[string]interface{}{
"username": terminal.EntityNameColor(cmd.configRepo.Username()),
}))
securityGroups, err := cmd.securityGroupRepo.FindAll()
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
cmd.ui.Say("")
if len(securityGroups) == 0 {
cmd.ui.Say(T("No security groups"))
return
}
table := terminal.NewTable(cmd.ui, []string{"", T("Name"), T("Organization"), T("Space")})
for index, securityGroup := range securityGroups {
if len(securityGroup.Spaces) > 0 {
cmd.printSpaces(table, securityGroup, index)
} else {
table.Add(fmt.Sprintf("#%d", index), securityGroup.Name, "", "")
}
}
table.Print()
}
示例4: Execute
func (cmd *ListApps) Execute(c flags.FlagContext) {
cmd.ui.Say(T("Getting apps in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
apps, apiErr := cmd.appSummaryRepo.GetSummariesInCurrentSpace()
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("")
if len(apps) == 0 {
cmd.ui.Say(T("No apps found"))
return
}
table := terminal.NewTable(cmd.ui, []string{
T("name"),
T("requested state"),
T("instances"),
T("memory"),
T("disk"),
T("app ports"),
T("urls"),
})
for _, application := range apps {
var urls []string
for _, route := range application.Routes {
urls = append(urls, route.URL())
}
appPorts := make([]string, len(application.AppPorts))
for i, p := range application.AppPorts {
appPorts[i] = strconv.Itoa(p)
}
table.Add(
application.Name,
ui_helpers.ColoredAppState(application.ApplicationFields),
ui_helpers.ColoredAppInstances(application.ApplicationFields),
formatters.ByteSize(application.Memory*formatters.MEGABYTE),
formatters.ByteSize(application.DiskQuota*formatters.MEGABYTE),
strings.Join(appPorts, ", "),
strings.Join(urls, ", "),
)
}
table.Print()
if cmd.pluginCall {
cmd.populatePluginModel(apps)
}
}
示例5: Run
func (cmd ListStack) Run(c *cli.Context) {
stackName := c.Args()[0]
stack, apiErr := cmd.stacksRepo.FindByName(stackName)
if c.Bool("guid") {
cmd.ui.Say(stack.Guid)
} else {
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Say(T("Getting stack '{{.Stack}}' in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{"Stack": stackName,
"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
cmd.ui.Ok()
cmd.ui.Say("")
table := terminal.NewTable(cmd.ui, []string{T("name"), T("description")})
table.Add(stack.Name, stack.Description)
table.Print()
}
}
示例6: Execute
func (cmd *ListFeatureFlags) Execute(c flags.FlagContext) {
cmd.ui.Say(T("Retrieving status of all flagged features as {{.Username}}...", map[string]interface{}{
"Username": terminal.EntityNameColor(cmd.config.Username())}))
flags, err := cmd.flagRepo.List()
if err != nil {
cmd.ui.Failed(err.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("")
table := terminal.NewTable(cmd.ui, []string{T("Features"), T("State")})
for _, flag := range flags {
table.Add(
flag.Name,
cmd.flagBoolToString(flag.Enabled),
)
}
table.Print()
return
}
示例7: Run
func (cmd ListStacks) Run(c *cli.Context) {
cmd.ui.Say("Getting stacks in org %s / space %s as %s...",
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(cmd.config.SpaceFields().Name),
terminal.EntityNameColor(cmd.config.Username()),
)
stacks, apiErr := cmd.stacksRepo.FindAll()
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("")
table := terminal.NewTable(cmd.ui, []string{"name", "description"})
for _, stack := range stacks {
table.Add([]string{
stack.Name,
stack.Description,
})
}
table.Print()
}
示例8: Execute
func (c *V3Apps) Execute(fc flags.FlagContext) {
applications, err := c.repository.GetApplications()
if err != nil {
c.ui.Failed(err.Error())
}
processes := make([][]models.V3Process, len(applications))
routes := make([][]models.V3Route, len(applications))
for i, app := range applications {
ps, err := c.repository.GetProcesses(app.Links.Processes.Href)
if err != nil {
c.ui.Failed(err.Error())
}
processes[i] = ps
rs, err := c.repository.GetRoutes(app.Links.Routes.Href)
if err != nil {
c.ui.Failed(err.Error())
}
routes[i] = rs
}
table := terminal.NewTable(c.ui, []string{T("name"), T("requested state"), T("instances"), T("memory"), T("disk"), T("urls")})
for i := range applications {
c.addRow(table, applications[i], processes[i], routes[i])
}
table.Print()
}
示例9: Run
func (cmd *SpaceQuota) Run(c *cli.Context) {
name := c.Args()[0]
cmd.ui.Say(T("Getting space quota {{.Quota}} info as {{.Username}}...",
map[string]interface{}{
"Quota": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
spaceQuota, apiErr := cmd.spaceQuotaRepo.FindByName(name)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("")
var megabytes string
table := terminal.NewTable(cmd.ui, []string{"", ""})
table.Add(T("total memory limit"), formatters.ByteSize(spaceQuota.MemoryLimit*formatters.MEGABYTE))
if spaceQuota.InstanceMemoryLimit == -1 {
megabytes = "-1"
} else {
megabytes = formatters.ByteSize(spaceQuota.InstanceMemoryLimit * formatters.MEGABYTE)
}
table.Add(T("instance memory limit"), megabytes)
table.Add(T("routes"), fmt.Sprintf("%d", spaceQuota.RoutesLimit))
table.Add(T("services"), fmt.Sprintf("%d", spaceQuota.ServicesLimit))
table.Add(T("non basic services"), formatters.Allowed(spaceQuota.NonBasicServicesAllowed))
table.Print()
}
示例10: Run
func (cmd *ListQuotas) Run(c *cli.Context) {
cmd.ui.Say(T("Getting quotas as {{.Username}}...", map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())}))
quotas, apiErr := cmd.quotaRepo.FindAll()
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("")
table := terminal.NewTable(cmd.ui, []string{T("name"), T("memory limit"), T("routes"), T("service instances"), T("paid service plans")})
for _, quota := range quotas {
table.Add([]string{
quota.Name,
formatters.ByteSize(quota.MemoryLimit * formatters.MEGABYTE),
fmt.Sprintf("%d", quota.RoutesLimit),
fmt.Sprintf("%d", quota.ServicesLimit),
formatters.Allowed(quota.NonBasicServicesAllowed),
})
}
table.Print()
}
示例11: Run
func (cmd *ServiceAccess) Run(c *cli.Context) {
brokerToFilter := c.String("b")
var brokers []models.ServiceBroker
var err error
if brokerToFilter != "" {
brokers, err = cmd.actor.GetBrokerWithDependencies(brokerToFilter)
} else {
brokers, err = cmd.actor.GetAllBrokersWithDependencies()
}
if err != nil {
cmd.ui.Failed(T("Failed fetching service brokers.\n%s"), err)
return
}
for _, serviceBroker := range brokers {
cmd.ui.Say(fmt.Sprintf(T("broker: %s"), serviceBroker.Name))
table := terminal.NewTable(cmd.ui, []string{"", T("service"), T("plan"), T("access"), T("orgs")})
for _, service := range serviceBroker.Services {
if len(service.Plans) > 0 {
for _, plan := range service.Plans {
table.Add("", service.Label, plan.Name, cmd.formatAccess(plan.Public, plan.OrgNames), strings.Join(plan.OrgNames, ","))
}
} else {
table.Add("", service.Label, "", "", "")
}
}
table.Print()
cmd.ui.Say("")
}
}
示例12: Run
func (cmd ListStacks) Run(c *cli.Context) {
cmd.ui.Say(T("Getting stacks in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
stacks, apiErr := cmd.stacksRepo.FindAll()
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("")
table := terminal.NewTable(cmd.ui, []string{T("name"), T("description")})
for _, stack := range stacks {
table.Add([]string{
stack.Name,
stack.Description,
})
}
table.Print()
}
示例13: Run
func (cmd *ServiceAccess) Run(c *cli.Context) {
brokers, err := cmd.actor.GetBrokersWithDependencies()
if err != nil {
cmd.ui.Failed("Failed fetching service brokers.\n%s", err)
return
}
for _, serviceBroker := range brokers {
cmd.ui.Say(fmt.Sprintf("broker: %s", serviceBroker.Name))
table := terminal.NewTable(cmd.ui, []string{"", "service", "plan", "access", "orgs"})
for _, service := range serviceBroker.Services {
if len(service.Plans) > 0 {
for _, plan := range service.Plans {
table.Add("", service.Label, plan.Name, cmd.formatAccess(plan.Public, plan.OrgNames), strings.Join(plan.OrgNames, ","))
}
} else {
table.Add("", service.Label, "", "", "")
}
}
table.Print()
cmd.ui.Say("")
}
}
示例14: WildcardCommandApps
func (cmd *Wildcard) WildcardCommandApps(cliConnection plugin.CliConnection, args []string) {
InitializeCliDependencies()
defer panic.HandlePanics()
cmd.getMatchedApps(cliConnection, args)
cmd.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())
table := terminal.NewTable(cmd.ui, []string{T("name"), T("requested state"), T("instances"), T("memory"), T("disk"), T("urls")})
for _, app := range cmd.matchedApps {
var urls []string
for _, route := range app.Routes {
if route.Host == "" {
urls = append(urls, route.Domain.Name)
}
urls = append(urls, fmt.Sprintf("%s.%s", route.Host, route.Domain.Name))
}
table.Add(
app.Name,
app.State,
strconv.Itoa(app.RunningInstances),
formatters.ByteSize(app.Memory*formatters.MEGABYTE),
formatters.ByteSize(app.DiskQuota*formatters.MEGABYTE),
strings.Join(urls, ", "),
)
}
table.Print()
}
示例15: Execute
func (cmd *showQuota) Execute(c flags.FlagContext) {
quotaName := c.Args()[0]
cmd.ui.Say(T("Getting quota {{.QuotaName}} info as {{.Username}}...", map[string]interface{}{"QuotaName": quotaName, "Username": cmd.config.Username()}))
quota, err := cmd.quotaRepo.FindByName(quotaName)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
var megabytes string
if quota.InstanceMemoryLimit == -1 {
megabytes = T("unlimited")
} else {
megabytes = formatters.ByteSize(quota.InstanceMemoryLimit * formatters.MEGABYTE)
}
servicesLimit := strconv.Itoa(quota.ServicesLimit)
if servicesLimit == "-1" {
servicesLimit = T("unlimited")
}
table := terminal.NewTable(cmd.ui, []string{"", ""})
table.Add(T("Total Memory"), formatters.ByteSize(quota.MemoryLimit*formatters.MEGABYTE))
table.Add(T("Instance Memory"), megabytes)
table.Add(T("Routes"), fmt.Sprintf("%d", quota.RoutesLimit))
table.Add(T("Services"), servicesLimit)
table.Add(T("Paid service plans"), formatters.Allowed(quota.NonBasicServicesAllowed))
table.Print()
}