Skip to content

Commit 362c55a

Browse files
committed
fix: address Sayan's review feedback
1. Return error (non-zero exit) for invalid --output value instead of just logging and returning nil - more script-friendly 2. Add "output" to allowedFlags in browsers create pool path so --output flag doesn't conflict with pool configuration
1 parent c5a11b5 commit 362c55a

10 files changed

Lines changed: 31 additions & 60 deletions

File tree

cmd/app.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func runAppList(cmd *cobra.Command, args []string) error {
6262
output, _ := cmd.Flags().GetString("output")
6363

6464
if output != "" && output != "json" {
65-
pterm.Error.Println("unsupported --output value: use 'json'")
66-
return nil
65+
return fmt.Errorf("unsupported --output value: use 'json'")
6766
}
6867

6968
// Determine pagination inputs: prefer page/per-page if provided; else map legacy --limit
@@ -220,8 +219,7 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
220219
output, _ := cmd.Flags().GetString("output")
221220

222221
if output != "" && output != "json" {
223-
pterm.Error.Println("unsupported --output value: use 'json'")
224-
return nil
222+
return fmt.Errorf("unsupported --output value: use 'json'")
225223
}
226224

227225
if output != "json" {

cmd/browser_pools.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ type BrowserPoolsListInput struct {
3535

3636
func (c BrowserPoolsCmd) List(ctx context.Context, in BrowserPoolsListInput) error {
3737
if in.Output != "" && in.Output != "json" {
38-
pterm.Error.Println("unsupported --output value: use 'json'")
39-
return nil
38+
return fmt.Errorf("unsupported --output value: use 'json'")
4039
}
4140

4241
pools, err := c.client.List(ctx)
@@ -100,8 +99,7 @@ type BrowserPoolsCreateInput struct {
10099

101100
func (c BrowserPoolsCmd) Create(ctx context.Context, in BrowserPoolsCreateInput) error {
102101
if in.Output != "" && in.Output != "json" {
103-
pterm.Error.Println("unsupported --output value: use 'json'")
104-
return nil
102+
return fmt.Errorf("unsupported --output value: use 'json'")
105103
}
106104

107105
params := kernel.BrowserPoolNewParams{
@@ -180,8 +178,7 @@ type BrowserPoolsGetInput struct {
180178

181179
func (c BrowserPoolsCmd) Get(ctx context.Context, in BrowserPoolsGetInput) error {
182180
if in.Output != "" && in.Output != "json" {
183-
pterm.Error.Println("unsupported --output value: use 'json'")
184-
return nil
181+
return fmt.Errorf("unsupported --output value: use 'json'")
185182
}
186183

187184
pool, err := c.client.Get(ctx, in.IDOrName)
@@ -244,8 +241,7 @@ type BrowserPoolsUpdateInput struct {
244241

245242
func (c BrowserPoolsCmd) Update(ctx context.Context, in BrowserPoolsUpdateInput) error {
246243
if in.Output != "" && in.Output != "json" {
247-
pterm.Error.Println("unsupported --output value: use 'json'")
248-
return nil
244+
return fmt.Errorf("unsupported --output value: use 'json'")
249245
}
250246

251247
params := kernel.BrowserPoolUpdateParams{}
@@ -347,8 +343,7 @@ type BrowserPoolsAcquireInput struct {
347343

348344
func (c BrowserPoolsCmd) Acquire(ctx context.Context, in BrowserPoolsAcquireInput) error {
349345
if in.Output != "" && in.Output != "json" {
350-
pterm.Error.Println("unsupported --output value: use 'json'")
351-
return nil
346+
return fmt.Errorf("unsupported --output value: use 'json'")
352347
}
353348

354349
params := kernel.BrowserPoolAcquireParams{}

cmd/browsers.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ type BrowsersListInput struct {
201201

202202
func (b BrowsersCmd) List(ctx context.Context, in BrowsersListInput) error {
203203
if in.Output != "" && in.Output != "json" {
204-
pterm.Error.Println("unsupported --output value: use 'json'")
205-
return nil
204+
return fmt.Errorf("unsupported --output value: use 'json'")
206205
}
207206

208207
params := kernel.BrowserListParams{}
@@ -290,8 +289,7 @@ func (b BrowsersCmd) List(ctx context.Context, in BrowsersListInput) error {
290289

291290
func (b BrowsersCmd) Create(ctx context.Context, in BrowsersCreateInput) error {
292291
if in.Output != "" && in.Output != "json" {
293-
pterm.Error.Println("unsupported --output value: use 'json'")
294-
return nil
292+
return fmt.Errorf("unsupported --output value: use 'json'")
295293
}
296294

297295
if in.Output != "json" {
@@ -475,8 +473,7 @@ func (b BrowsersCmd) Delete(ctx context.Context, in BrowsersDeleteInput) error {
475473

476474
func (b BrowsersCmd) View(ctx context.Context, in BrowsersViewInput) error {
477475
if in.Output != "" && in.Output != "json" {
478-
pterm.Error.Println("unsupported --output value: use 'json'")
479-
return nil
476+
return fmt.Errorf("unsupported --output value: use 'json'")
480477
}
481478

482479
browser, err := b.browsers.Get(ctx, in.Identifier)
@@ -506,8 +503,7 @@ func (b BrowsersCmd) View(ctx context.Context, in BrowsersViewInput) error {
506503

507504
func (b BrowsersCmd) Get(ctx context.Context, in BrowsersGetInput) error {
508505
if in.Output != "" && in.Output != "json" {
509-
pterm.Error.Println("unsupported --output value: use 'json'")
510-
return nil
506+
return fmt.Errorf("unsupported --output value: use 'json'")
511507
}
512508

513509
browser, err := b.browsers.Get(ctx, in.Identifier)
@@ -909,8 +905,7 @@ type BrowsersReplaysDownloadInput struct {
909905

910906
func (b BrowsersCmd) ReplaysList(ctx context.Context, in BrowsersReplaysListInput) error {
911907
if in.Output != "" && in.Output != "json" {
912-
pterm.Error.Println("unsupported --output value: use 'json'")
913-
return nil
908+
return fmt.Errorf("unsupported --output value: use 'json'")
914909
}
915910

916911
br, err := b.browsers.Get(ctx, in.Identifier)
@@ -949,8 +944,7 @@ func (b BrowsersCmd) ReplaysList(ctx context.Context, in BrowsersReplaysListInpu
949944

950945
func (b BrowsersCmd) ReplaysStart(ctx context.Context, in BrowsersReplaysStartInput) error {
951946
if in.Output != "" && in.Output != "json" {
952-
pterm.Error.Println("unsupported --output value: use 'json'")
953-
return nil
947+
return fmt.Errorf("unsupported --output value: use 'json'")
954948
}
955949

956950
br, err := b.browsers.Get(ctx, in.Identifier)
@@ -1121,8 +1115,7 @@ func (b BrowsersCmd) PlaywrightExecute(ctx context.Context, in BrowsersPlaywrigh
11211115

11221116
func (b BrowsersCmd) ProcessExec(ctx context.Context, in BrowsersProcessExecInput) error {
11231117
if in.Output != "" && in.Output != "json" {
1124-
pterm.Error.Println("unsupported --output value: use 'json'")
1125-
return nil
1118+
return fmt.Errorf("unsupported --output value: use 'json'")
11261119
}
11271120

11281121
if b.process == nil {
@@ -1194,8 +1187,7 @@ func (b BrowsersCmd) ProcessExec(ctx context.Context, in BrowsersProcessExecInpu
11941187

11951188
func (b BrowsersCmd) ProcessSpawn(ctx context.Context, in BrowsersProcessSpawnInput) error {
11961189
if in.Output != "" && in.Output != "json" {
1197-
pterm.Error.Println("unsupported --output value: use 'json'")
1198-
return nil
1190+
return fmt.Errorf("unsupported --output value: use 'json'")
11991191
}
12001192

12011193
if b.process == nil {
@@ -1499,8 +1491,7 @@ func (b BrowsersCmd) FSDownloadDirZip(ctx context.Context, in BrowsersFSDownload
14991491

15001492
func (b BrowsersCmd) FSFileInfo(ctx context.Context, in BrowsersFSFileInfoInput) error {
15011493
if in.Output != "" && in.Output != "json" {
1502-
pterm.Error.Println("unsupported --output value: use 'json'")
1503-
return nil
1494+
return fmt.Errorf("unsupported --output value: use 'json'")
15041495
}
15051496

15061497
if b.fs == nil {
@@ -1532,8 +1523,7 @@ func (b BrowsersCmd) FSFileInfo(ctx context.Context, in BrowsersFSFileInfoInput)
15321523

15331524
func (b BrowsersCmd) FSListFiles(ctx context.Context, in BrowsersFSListFilesInput) error {
15341525
if in.Output != "" && in.Output != "json" {
1535-
pterm.Error.Println("unsupported --output value: use 'json'")
1536-
return nil
1526+
return fmt.Errorf("unsupported --output value: use 'json'")
15371527
}
15381528

15391529
if b.fs == nil {
@@ -2178,6 +2168,7 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error {
21782168
"pool-id": true,
21792169
"pool-name": true,
21802170
"timeout": true,
2171+
"output": true,
21812172
// Global persistent flags that don't configure browsers
21822173
"no-color": true,
21832174
"log-level": true,

cmd/deploy.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ func runDeployGithub(cmd *cobra.Command, args []string) error {
9797
output, _ := cmd.Flags().GetString("output")
9898

9999
if output != "" && output != "json" {
100-
pterm.Error.Println("unsupported --output value: use 'json'")
101-
return nil
100+
return fmt.Errorf("unsupported --output value: use 'json'")
102101
}
103102

104103
// Collect env vars similar to runDeploy
@@ -216,8 +215,7 @@ func runDeploy(cmd *cobra.Command, args []string) (err error) {
216215
output, _ := cmd.Flags().GetString("output")
217216

218217
if output != "" && output != "json" {
219-
pterm.Error.Println("unsupported --output value: use 'json'")
220-
return nil
218+
return fmt.Errorf("unsupported --output value: use 'json'")
221219
}
222220

223221
if version == "" {
@@ -388,8 +386,7 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
388386
output, _ := cmd.Flags().GetString("output")
389387

390388
if output != "" && output != "json" {
391-
pterm.Error.Println("unsupported --output value: use 'json'")
392-
return nil
389+
return fmt.Errorf("unsupported --output value: use 'json'")
393390
}
394391

395392
// Prefer page/per-page when provided; map legacy --limit otherwise

cmd/extensions.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ type ExtensionsCmd struct {
6060

6161
func (e ExtensionsCmd) List(ctx context.Context, in ExtensionsListInput) error {
6262
if in.Output != "" && in.Output != "json" {
63-
pterm.Error.Println("unsupported --output value: use 'json'")
64-
return nil
63+
return fmt.Errorf("unsupported --output value: use 'json'")
6564
}
6665

6766
if in.Output != "json" {
@@ -285,8 +284,7 @@ func (e ExtensionsCmd) DownloadWebStore(ctx context.Context, in ExtensionsDownlo
285284

286285
func (e ExtensionsCmd) Upload(ctx context.Context, in ExtensionsUploadInput) error {
287286
if in.Output != "" && in.Output != "json" {
288-
pterm.Error.Println("unsupported --output value: use 'json'")
289-
return nil
287+
return fmt.Errorf("unsupported --output value: use 'json'")
290288
}
291289

292290
if in.Dir == "" {

cmd/invoke.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func runInvoke(cmd *cobra.Command, args []string) error {
6262
output, _ := cmd.Flags().GetString("output")
6363

6464
if output != "" && output != "json" {
65-
pterm.Error.Println("unsupported --output value: use 'json'")
66-
return nil
65+
return fmt.Errorf("unsupported --output value: use 'json'")
6766
}
6867
jsonOutput := output == "json"
6968

@@ -337,8 +336,7 @@ func runInvocationHistory(cmd *cobra.Command, args []string) error {
337336
output, _ := cmd.Flags().GetString("output")
338337

339338
if output != "" && output != "json" {
340-
pterm.Error.Println("unsupported --output value: use 'json'")
341-
return nil
339+
return fmt.Errorf("unsupported --output value: use 'json'")
342340
}
343341

344342
// Build parameters for the API call

cmd/profiles.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ type ProfilesCmd struct {
5757

5858
func (p ProfilesCmd) List(ctx context.Context, in ProfilesListInput) error {
5959
if in.Output != "" && in.Output != "json" {
60-
pterm.Error.Println("unsupported --output value: use 'json'")
61-
return nil
60+
return fmt.Errorf("unsupported --output value: use 'json'")
6261
}
6362

6463
if in.Output != "json" {
@@ -106,8 +105,7 @@ func (p ProfilesCmd) List(ctx context.Context, in ProfilesListInput) error {
106105

107106
func (p ProfilesCmd) Get(ctx context.Context, in ProfilesGetInput) error {
108107
if in.Output != "" && in.Output != "json" {
109-
pterm.Error.Println("unsupported --output value: use 'json'")
110-
return nil
108+
return fmt.Errorf("unsupported --output value: use 'json'")
111109
}
112110

113111
item, err := p.profiles.Get(ctx, in.Identifier)
@@ -148,8 +146,7 @@ func (p ProfilesCmd) Get(ctx context.Context, in ProfilesGetInput) error {
148146

149147
func (p ProfilesCmd) Create(ctx context.Context, in ProfilesCreateInput) error {
150148
if in.Output != "" && in.Output != "json" {
151-
pterm.Error.Println("unsupported --output value: use 'json'")
152-
return nil
149+
return fmt.Errorf("unsupported --output value: use 'json'")
153150
}
154151

155152
params := kernel.ProfileNewParams{}

cmd/proxies/create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414

1515
func (p ProxyCmd) Create(ctx context.Context, in ProxyCreateInput) error {
1616
if in.Output != "" && in.Output != "json" {
17-
pterm.Error.Println("unsupported --output value: use 'json'")
18-
return nil
17+
return fmt.Errorf("unsupported --output value: use 'json'")
1918
}
2019

2120
// Validate proxy type

cmd/proxies/get.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414

1515
func (p ProxyCmd) Get(ctx context.Context, in ProxyGetInput) error {
1616
if in.Output != "" && in.Output != "json" {
17-
pterm.Error.Println("unsupported --output value: use 'json'")
18-
return nil
17+
return fmt.Errorf("unsupported --output value: use 'json'")
1918
}
2019

2120
item, err := p.proxies.Get(ctx, in.ID)

cmd/proxies/list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import (
1515

1616
func (p ProxyCmd) List(ctx context.Context, in ProxyListInput) error {
1717
if in.Output != "" && in.Output != "json" {
18-
pterm.Error.Println("unsupported --output value: use 'json'")
19-
return nil
18+
return fmt.Errorf("unsupported --output value: use 'json'")
2019
}
2120

2221
if in.Output != "json" {

0 commit comments

Comments
 (0)