Skip to content

Commit

Permalink
v8(services): services cmd - remove experimental formats (#2136)
Browse files Browse the repository at this point in the history
We experimented with some different formatting options and in the end
decided to keep the existing format

[#176843213](https://www.pivotaltracker.com/story/show/176843213)
  • Loading branch information
blgm authored Feb 10, 2021
1 parent 82601ed commit 009f412
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 68 deletions.
16 changes: 8 additions & 8 deletions actor/v7action/service_instance_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
)

type ServiceInstance struct {
Type resources.ServiceInstanceType `json:"type,omitempty"`
Name string `json:"name"`
ServicePlanName string `json:"plan,omitempty"`
ServiceOfferingName string `json:"offering,omitempty"`
ServiceBrokerName string `json:"broker,omitempty"`
BoundApps []string `json:"bound_apps,omitempty"`
LastOperation string `json:"last_operation,omitempty"`
UpgradeAvailable types.OptionalBoolean `json:"upgrade_available"`
Type resources.ServiceInstanceType
Name string
ServicePlanName string
ServiceOfferingName string
ServiceBrokerName string
BoundApps []string
LastOperation string
UpgradeAvailable types.OptionalBoolean
}

type planDetails struct {
Expand Down
62 changes: 2 additions & 60 deletions command/v7/services_command.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v7

import (
"encoding/json"
"strings"

"code.cloudfoundry.org/cli/resources"
Expand All @@ -14,7 +13,6 @@ import (
type ServicesCommand struct {
BaseCommand

Format string `long:"format" hidden:"yes"`
OmitApps bool `long:"no-apps" description:"Do not retrieve bound apps information."`
relatedCommands interface{} `related_commands:"create-service, marketplace"`
}
Expand All @@ -34,15 +32,7 @@ func (cmd ServicesCommand) Execute(args []string) error {
return err
}

switch cmd.Format {
case "json":
cmd.displayJSON(instances)
case "split":
cmd.displaySplitTable(instances)
default:
cmd.displayHeritageTable(instances)
}

cmd.displayTable(instances)
return nil
}

Expand All @@ -66,7 +56,7 @@ func (cmd ServicesCommand) displayMessage() error {
return nil
}

func (cmd ServicesCommand) displayHeritageTable(instances []v7action.ServiceInstance) {
func (cmd ServicesCommand) displayTable(instances []v7action.ServiceInstance) {
if len(instances) == 0 {
cmd.UI.DisplayText("No service instances found.")
return
Expand All @@ -80,54 +70,6 @@ func (cmd ServicesCommand) displayHeritageTable(instances []v7action.ServiceInst
cmd.UI.DisplayTableWithHeader("", table.table, ui.DefaultTableSpacePadding)
}

func (cmd ServicesCommand) displaySplitTable(instances []v7action.ServiceInstance) {
if len(instances) == 0 {
cmd.UI.DisplayText("No service instances found.")
return
}

var managed, user []v7action.ServiceInstance
for _, i := range instances {
if i.Type == resources.UserProvidedServiceInstance {
user = append(user, i)
} else {
managed = append(managed, i)
}
}

if len(managed) > 0 {
table := NewServicesTable(false, cmd.OmitApps)
for _, si := range managed {
table.AppendRow(si)
}
cmd.UI.DisplayText("Managed service instances:")
cmd.UI.DisplayTableWithHeader(" ", table.table, ui.DefaultTableSpacePadding)

if len(user) > 0 {
cmd.UI.DisplayNewline()
}
}

if len(user) > 0 {
table := NewServicesTable(true, cmd.OmitApps)
for _, si := range user {
table.AppendRow(si)
//table = append(table, []string{i.Name, strings.Join(i.BoundApps, ", ")})
}
cmd.UI.DisplayText("User-provided service instances:")
cmd.UI.DisplayTableWithHeader(" ", table.table, ui.DefaultTableSpacePadding)
}
}

func (cmd ServicesCommand) displayJSON(instances []v7action.ServiceInstance) {
data, err := json.MarshalIndent(instances, "", " ")
if err != nil {
panic(err)
}

cmd.UI.DisplayText(string(data))
}

func upgradeAvailableString(u types.OptionalBoolean) string {
switch {
case u.IsSet && u.Value:
Expand Down
2 changes: 2 additions & 0 deletions integration/v7/isolated/services_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ var _ = Describe("services command V3", func() {
Say(`cf services\n`),
Say(`ALIAS:\n`),
Say(`s\n`),
Say(`OPTIONS:\n`),
Say(`--no-apps\s+Do not retrieve bound apps information\.\n`),
Say(`SEE ALSO:\n`),
Say(`create-service, marketplace\n`),
)
Expand Down

0 comments on commit 009f412

Please sign in to comment.