Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions pkg/cli/tabular.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import (
)

func NewTabular(rows ...[]string) table.Model {
columnKeyProperty := "Property"
columnKeyValue := "Value"
t := NewTable(
table.NewColumn("property", "Property", 15),
table.NewColumn("value", "Value", 15),
table.NewColumn(columnKeyProperty, columnKeyProperty, 37),
table.NewColumn(columnKeyValue, columnKeyValue, 37),
)

tr := []table.Row{}
if len(rows) == 0 {
tr = append(tr, table.NewRow(table.RowData{
"property": "No properties found",
"value": "",
columnKeyProperty: "No properties found",
columnKeyValue: "",
}))
}
for _, r := range rows {
Expand All @@ -28,11 +30,12 @@ func NewTabular(rows ...[]string) table.Model {
v = r[1]
}
tr = append(tr, table.NewRow(table.RowData{
"property": p,
"value": v,
columnKeyProperty: p,
columnKeyValue: v,
}))
}

t = t.WithRows(tr)
return t
}

Expand All @@ -42,6 +45,7 @@ func getJsonHelper(command string) string {

func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) {
parent := cmd.Parent()
resourceShort := parent.Use
resource := parent.Use
for parent.Parent() != nil {
resource = parent.Parent().Use + " " + resource
Expand All @@ -54,22 +58,22 @@ func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) {
}
switch cmd.Use {
case ActionGet:
msg.verb = fmt.Sprintf("Found %s: %s", resource, id)
msg.verb = fmt.Sprintf("Found %s: %s", resourceShort, id)
msg.helper = getJsonHelper(resource + " get --id=" + id)
case ActionCreate:
msg.verb = fmt.Sprintf("Created %s: %s", resource, id)
msg.verb = fmt.Sprintf("Created %s: %s", resourceShort, id)
msg.helper = getJsonHelper(resource + " get --id=" + id)
case ActionUpdate:
msg.verb = fmt.Sprintf("Updated %s: %s", resource, id)
msg.verb = fmt.Sprintf("Updated %s: %s", resourceShort, id)
msg.helper = getJsonHelper(resource + " get --id=" + id)
case ActionDelete:
msg.verb = fmt.Sprintf("Deleted %s: %s", resource, id)
msg.verb = fmt.Sprintf("Deleted %s: %s", resourceShort, id)
msg.helper = getJsonHelper(resource + " list")
case ActionDeactivate:
msg.verb = fmt.Sprintf("Deactivated %s: %s", resource, id)
msg.verb = fmt.Sprintf("Deactivated %s: %s", resourceShort, id)
msg.helper = getJsonHelper(resource + " list") // TODO: make sure the filters are provided here to get ACTIVE/INACTIVE/ANY
case ActionList:
msg.verb = fmt.Sprintf("Found %s list", resource)
msg.verb = fmt.Sprintf("Found %s list", resourceShort)
msg.helper = getJsonHelper(resource + " get --id=<id>")
default:
msg.verb = ""
Expand Down