Skip to content

Commit a92b94b

Browse files
committed
feat(service): add --json flag as no-op alias for --format json
1 parent 691f694 commit a92b94b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

cmd/service/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func NewCmdServiceMethodWithContext(ctx context.Context, f *cmdutil.Factory, spe
178178
cmd.Flags().IntVar(&opts.PageLimit, "page-limit", 10, "max pages to fetch with --page-all (0 = unlimited)")
179179
cmd.Flags().IntVar(&opts.PageDelay, "page-delay", 200, "delay in ms between pages")
180180
cmd.Flags().StringVar(&opts.Format, "format", "json", "output format: json|ndjson|table|csv")
181+
cmd.Flags().Bool("json", false, "shorthand for --format json")
181182
cmd.Flags().StringVarP(&opts.JqExpr, "jq", "q", "", "jq expression to filter JSON output")
182183
cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "print request without executing")
183184
if risk == "high-risk-write" {

cmd/service/service_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,25 @@ func TestDetectFileFields(t *testing.T) {
867867
}
868868
}
869869

870+
func TestServiceMethod_JsonFlag_Accepted(t *testing.T) {
871+
f, _, _, _ := cmdutil.TestFactory(t, testConfig)
872+
873+
var captured *ServiceMethodOptions
874+
cmd := NewCmdServiceMethod(f, driveSpec(),
875+
map[string]interface{}{"description": "desc", "httpMethod": "GET"}, "list", "files",
876+
func(opts *ServiceMethodOptions) error {
877+
captured = opts
878+
return nil
879+
})
880+
cmd.SetArgs([]string{"--json"})
881+
if err := cmd.Execute(); err != nil {
882+
t.Fatalf("--json should be accepted without error, got: %v", err)
883+
}
884+
if captured == nil {
885+
t.Fatal("expected runF to be called")
886+
}
887+
}
888+
870889
// ── helpers ──
871890

872891
func isExitError(err error, target **output.ExitError) bool {

0 commit comments

Comments
 (0)