Skip to content

Commit df157b4

Browse files
Add format option to ingress list command (#27)
The global options were not respected. With this change, all of the formatting options are respected.
1 parent 66895eb commit df157b4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/cmd/ingresscmd.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/kernel/hypeman-go"
1010
"github.com/kernel/hypeman-go/option"
11+
"github.com/tidwall/gjson"
1112
"github.com/urfave/cli/v3"
1213
)
1314

@@ -146,6 +147,21 @@ func handleIngressList(ctx context.Context, cmd *cli.Command) error {
146147
opts = append(opts, debugMiddlewareOption)
147148
}
148149

150+
format := cmd.Root().String("format")
151+
transform := cmd.Root().String("transform")
152+
153+
// If a specific format is requested (not "auto"), output in that format
154+
if format != "auto" {
155+
var res []byte
156+
opts = append(opts, option.WithResponseBodyInto(&res))
157+
_, err := client.Ingresses.List(ctx, opts...)
158+
if err != nil {
159+
return err
160+
}
161+
obj := gjson.ParseBytes(res)
162+
return ShowJSON(os.Stdout, "ingress list", obj, format, transform)
163+
}
164+
149165
ingresses, err := client.Ingresses.List(ctx, opts...)
150166
if err != nil {
151167
return err

0 commit comments

Comments
 (0)