Skip to content

Commit dcd0dc6

Browse files
committed
feat: CLI list commands default to summary JSON output with --full flag
Signed-off-by: Vukotije <vukanradojevicc@gmail.com>
1 parent 4427fec commit dcd0dc6

File tree

8 files changed

+132
-13
lines changed

8 files changed

+132
-13
lines changed

pkg/cli/commands/canvases/list.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"github.com/superplanehq/superplane/pkg/cli/core"
1111
)
1212

13-
type listCommand struct{}
13+
type listCommand struct {
14+
full *bool
15+
}
1416

1517
func (c *listCommand) Execute(ctx core.CommandContext) error {
1618
response, _, err := ctx.API.CanvasAPI.CanvasesListCanvases(ctx.Context).Execute()
@@ -25,7 +27,24 @@ func (c *listCommand) Execute(ctx core.CommandContext) error {
2527
}
2628

2729
if !ctx.Renderer.IsText() {
28-
return ctx.Renderer.Render(resources)
30+
if c.full != nil && *c.full {
31+
return ctx.Renderer.Render(resources)
32+
}
33+
34+
summary := make([]map[string]string, len(canvases))
35+
for i, canvas := range canvases {
36+
metadata := canvas.GetMetadata()
37+
createdAt := ""
38+
if metadata.HasCreatedAt() {
39+
createdAt = metadata.GetCreatedAt().Format(time.RFC3339)
40+
}
41+
summary[i] = map[string]string{
42+
"id": metadata.GetId(),
43+
"name": metadata.GetName(),
44+
"createdAt": createdAt,
45+
}
46+
}
47+
return ctx.Renderer.Render(summary)
2948
}
3049

3150
return ctx.Renderer.RenderText(func(stdout io.Writer) error {

pkg/cli/commands/canvases/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func NewCommand(options core.BindOptions) *cobra.Command {
1818
Short: "List canvases",
1919
Args: cobra.NoArgs,
2020
}
21-
core.Bind(listCmd, &listCommand{}, options)
21+
var listFull bool
22+
listCmd.Flags().BoolVar(&listFull, "full", false, "show full output including all fields")
23+
core.Bind(listCmd, &listCommand{full: &listFull}, options)
2224

2325
getCmd := &cobra.Command{
2426
Use: "get <name-or-id>",

pkg/cli/commands/events/list.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ListEventsCommand struct {
1414
NodeID *string
1515
Limit *int64
1616
Before *string
17+
Full *bool
1718
}
1819

1920
func (c *ListEventsCommand) Execute(ctx core.CommandContext) error {
@@ -52,7 +53,20 @@ func (c *ListEventsCommand) listNodeEvents(ctx core.CommandContext) error {
5253
}
5354

5455
if !ctx.Renderer.IsText() {
55-
return ctx.Renderer.Render(response)
56+
if c.Full != nil && *c.Full {
57+
return ctx.Renderer.Render(response)
58+
}
59+
60+
events := response.GetEvents()
61+
summary := make([]map[string]string, len(events))
62+
for i, event := range events {
63+
summary[i] = map[string]string{
64+
"id": event.GetId(),
65+
"channel": event.GetChannel(),
66+
"createdAt": event.GetCreatedAt().Format(time.RFC3339),
67+
}
68+
}
69+
return ctx.Renderer.Render(summary)
5670
}
5771

5872
return ctx.Renderer.RenderText(func(stdout io.Writer) error {
@@ -106,7 +120,22 @@ func (c *ListEventsCommand) listCanvasEvents(ctx core.CommandContext) error {
106120
}
107121

108122
if !ctx.Renderer.IsText() {
109-
return ctx.Renderer.Render(response)
123+
if c.Full != nil && *c.Full {
124+
return ctx.Renderer.Render(response)
125+
}
126+
127+
events := response.GetEvents()
128+
summary := make([]map[string]any, len(events))
129+
for i, event := range events {
130+
summary[i] = map[string]any{
131+
"id": event.GetId(),
132+
"nodeId": event.GetNodeId(),
133+
"channel": event.GetChannel(),
134+
"executions": len(event.GetExecutions()),
135+
"createdAt": event.GetCreatedAt().Format(time.RFC3339),
136+
}
137+
}
138+
return ctx.Renderer.Render(summary)
110139
}
111140

112141
return ctx.Renderer.RenderText(func(stdout io.Writer) error {

pkg/cli/commands/events/list_executions.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
type ListEventExecutionsCommand struct {
1313
CanvasID *string
1414
EventID *string
15+
Full *bool
1516
}
1617

1718
func (c *ListEventExecutionsCommand) Execute(ctx core.CommandContext) error {
@@ -28,7 +29,23 @@ func (c *ListEventExecutionsCommand) Execute(ctx core.CommandContext) error {
2829
}
2930

3031
if !ctx.Renderer.IsText() {
31-
return ctx.Renderer.Render(response)
32+
if c.Full != nil && *c.Full {
33+
return ctx.Renderer.Render(response)
34+
}
35+
36+
executions := response.GetExecutions()
37+
summary := make([]map[string]string, len(executions))
38+
for i, execution := range executions {
39+
summary[i] = map[string]string{
40+
"id": execution.GetId(),
41+
"nodeId": execution.GetNodeId(),
42+
"state": string(execution.GetState()),
43+
"result": string(execution.GetResult()),
44+
"createdAt": execution.GetCreatedAt().Format(time.RFC3339),
45+
"updatedAt": execution.GetUpdatedAt().Format(time.RFC3339),
46+
}
47+
}
48+
return ctx.Renderer.Render(summary)
3249
}
3350

3451
return ctx.Renderer.RenderText(func(stdout io.Writer) error {

pkg/cli/commands/events/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ func NewCommand(options core.BindOptions) *cobra.Command {
2626
Short: "List root events for a canvas or events for a specific node",
2727
Args: cobra.NoArgs,
2828
}
29+
var listFull bool
2930
listCmd.Flags().StringVar(&canvasID, "canvas-id", "", "canvas ID")
3031
listCmd.Flags().StringVar(&nodeID, "node-id", "", "node ID")
3132
listCmd.Flags().Int64Var(&limit, "limit", 20, "maximum number of items to return")
3233
listCmd.Flags().StringVar(&before, "before", "", "return items before this timestamp (RFC3339)")
34+
listCmd.Flags().BoolVar(&listFull, "full", false, "show full output including all fields")
3335
core.Bind(listCmd, &ListEventsCommand{
3436
CanvasID: &canvasID,
3537
NodeID: &nodeID,
3638
Limit: &limit,
3739
Before: &before,
40+
Full: &listFull,
3841
}, options)
3942

4043
//
@@ -45,12 +48,15 @@ func NewCommand(options core.BindOptions) *cobra.Command {
4548
Short: "List executions for a root event",
4649
Args: cobra.NoArgs,
4750
}
51+
var listExecFull bool
4852
listExecutionsCmd.Flags().StringVar(&canvasID, "canvas-id", "", "canvas ID")
4953
listExecutionsCmd.Flags().StringVar(&eventID, "event-id", "", "event ID")
54+
listExecutionsCmd.Flags().BoolVar(&listExecFull, "full", false, "show full output including all fields")
5055
_ = listExecutionsCmd.MarkFlagRequired("event-id")
5156
core.Bind(listExecutionsCmd, &ListEventExecutionsCommand{
5257
CanvasID: &canvasID,
5358
EventID: &eventID,
59+
Full: &listExecFull,
5460
}, options)
5561

5662
root.AddCommand(listCmd)

pkg/cli/commands/index/components.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
func newComponentsCommand(options core.BindOptions) *cobra.Command {
1616
var from string
1717
var name string
18+
var full bool
1819

1920
cmd := &cobra.Command{
2021
Use: "components",
@@ -23,14 +24,16 @@ func newComponentsCommand(options core.BindOptions) *cobra.Command {
2324
}
2425
cmd.Flags().StringVar(&from, "from", "", "integration definition name")
2526
cmd.Flags().StringVar(&name, "name", "", "component name")
26-
core.Bind(cmd, &componentsCommand{from: &from, name: &name}, options)
27+
cmd.Flags().BoolVar(&full, "full", false, "show full output including all fields")
28+
core.Bind(cmd, &componentsCommand{from: &from, name: &name, full: &full}, options)
2729

2830
return cmd
2931
}
3032

3133
type componentsCommand struct {
3234
from *string
3335
name *string
36+
full *bool
3437
}
3538

3639
func (c *componentsCommand) Execute(ctx core.CommandContext) error {
@@ -47,7 +50,19 @@ func (c *componentsCommand) Execute(ctx core.CommandContext) error {
4750
}
4851

4952
if !ctx.Renderer.IsText() {
50-
return ctx.Renderer.Render(components)
53+
if c.full != nil && *c.full {
54+
return ctx.Renderer.Render(components)
55+
}
56+
57+
summary := make([]map[string]string, len(components))
58+
for i, component := range components {
59+
summary[i] = map[string]string{
60+
"name": component.GetName(),
61+
"label": component.GetLabel(),
62+
"description": component.GetDescription(),
63+
}
64+
}
65+
return ctx.Renderer.Render(summary)
5166
}
5267

5368
return ctx.Renderer.RenderText(func(stdout io.Writer) error {

pkg/cli/commands/index/integrations.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ import (
1313

1414
func newIntegrationsCommand(options core.BindOptions) *cobra.Command {
1515
var name string
16+
var full bool
1617

1718
cmd := &cobra.Command{
1819
Use: "integrations",
1920
Short: "List or describe available integration definitions",
2021
Args: cobra.NoArgs,
2122
}
2223
cmd.Flags().StringVar(&name, "name", "", "integration definition name")
23-
core.Bind(cmd, &integrationsCommand{name: &name}, options)
24+
cmd.Flags().BoolVar(&full, "full", false, "show full output including all fields")
25+
core.Bind(cmd, &integrationsCommand{name: &name, full: &full}, options)
2426

2527
return cmd
2628
}
2729

2830
type integrationsCommand struct {
2931
name *string
32+
full *bool
3033
}
3134

3235
func (c *integrationsCommand) Execute(ctx core.CommandContext) error {
@@ -40,14 +43,27 @@ func (c *integrationsCommand) Execute(ctx core.CommandContext) error {
4043
return err
4144
}
4245

46+
integrations := response.GetIntegrations()
4347
if !ctx.Renderer.IsText() {
44-
return ctx.Renderer.Render(response.GetIntegrations())
48+
if c.full != nil && *c.full {
49+
return ctx.Renderer.Render(integrations)
50+
}
51+
52+
summary := make([]map[string]string, len(integrations))
53+
for i, integration := range integrations {
54+
summary[i] = map[string]string{
55+
"name": integration.GetName(),
56+
"label": integration.GetLabel(),
57+
"description": integration.GetDescription(),
58+
}
59+
}
60+
return ctx.Renderer.Render(summary)
4561
}
4662

4763
return ctx.Renderer.RenderText(func(stdout io.Writer) error {
4864
writer := tabwriter.NewWriter(stdout, 0, 8, 2, ' ', 0)
4965
_, _ = fmt.Fprintln(writer, "NAME\tLABEL\tDESCRIPTION")
50-
for _, integration := range response.GetIntegrations() {
66+
for _, integration := range integrations {
5167
_, _ = fmt.Fprintf(writer, "%s\t%s\t%s\n", integration.GetName(), integration.GetLabel(), integration.GetDescription())
5268
}
5369
return writer.Flush()

pkg/cli/commands/index/triggers.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func newTriggersCommand(options core.BindOptions) *cobra.Command {
1515
var from string
1616
var name string
17+
var full bool
1718

1819
cmd := &cobra.Command{
1920
Use: "triggers",
@@ -22,14 +23,16 @@ func newTriggersCommand(options core.BindOptions) *cobra.Command {
2223
}
2324
cmd.Flags().StringVar(&from, "from", "", "integration definition name")
2425
cmd.Flags().StringVar(&name, "name", "", "trigger name")
25-
core.Bind(cmd, &triggersCommand{from: &from, name: &name}, options)
26+
cmd.Flags().BoolVar(&full, "full", false, "show full output including all fields")
27+
core.Bind(cmd, &triggersCommand{from: &from, name: &name, full: &full}, options)
2628

2729
return cmd
2830
}
2931

3032
type triggersCommand struct {
3133
from *string
3234
name *string
35+
full *bool
3336
}
3437

3538
func (c *triggersCommand) Execute(ctx core.CommandContext) error {
@@ -46,7 +49,19 @@ func (c *triggersCommand) Execute(ctx core.CommandContext) error {
4649
}
4750

4851
if !ctx.Renderer.IsText() {
49-
return ctx.Renderer.Render(triggers)
52+
if c.full != nil && *c.full {
53+
return ctx.Renderer.Render(triggers)
54+
}
55+
56+
summary := make([]map[string]string, len(triggers))
57+
for i, trigger := range triggers {
58+
summary[i] = map[string]string{
59+
"name": trigger.GetName(),
60+
"label": trigger.GetLabel(),
61+
"description": trigger.GetDescription(),
62+
}
63+
}
64+
return ctx.Renderer.Render(summary)
5065
}
5166

5267
return ctx.Renderer.RenderText(func(stdout io.Writer) error {

0 commit comments

Comments
 (0)