Skip to content

Commit c30b482

Browse files
committed
switch defaults for pr view
1 parent 74a2a24 commit c30b482

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

command/pr.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func init() {
3131
prListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
3232
prListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee")
3333

34-
prViewCmd.Flags().BoolP("preview", "p", false, "Display preview of pull request content")
34+
prViewCmd.Flags().BoolP("web", "w", false, "Open pull request in browser")
3535
}
3636

3737
var prCmd = &cobra.Command{
@@ -262,7 +262,7 @@ func prView(cmd *cobra.Command, args []string) error {
262262
return err
263263
}
264264

265-
preview, err := cmd.Flags().GetBool("preview")
265+
web, err := cmd.Flags().GetBool("web")
266266
if err != nil {
267267
return err
268268
}
@@ -283,7 +283,7 @@ func prView(cmd *cobra.Command, args []string) error {
283283

284284
if prNumber > 0 {
285285
openURL = fmt.Sprintf("https://github.com/%s/pull/%d", ghrepo.FullName(baseRepo), prNumber)
286-
if preview {
286+
if !web {
287287
pr, err = api.PullRequestByNumber(apiClient, baseRepo, prNumber)
288288
if err != nil {
289289
return err
@@ -299,12 +299,12 @@ func prView(cmd *cobra.Command, args []string) error {
299299
}
300300
}
301301

302-
if preview {
303-
out := colorableOut(cmd)
304-
return printPrPreview(out, pr)
305-
} else {
302+
if web {
306303
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
307304
return utils.OpenInBrowser(openURL)
305+
} else {
306+
out := colorableOut(cmd)
307+
return printPrPreview(out, pr)
308308
}
309309
}
310310

command/pr_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func TestPRView_preview(t *testing.T) {
391391
defer jsonFile.Close()
392392
http.StubResponse(200, jsonFile)
393393

394-
output, err := RunCommand(prViewCmd, "pr view -p 12")
394+
output, err := RunCommand(prViewCmd, "pr view 12")
395395
if err != nil {
396396
t.Errorf("error running command `pr view`: %v", err)
397397
}
@@ -426,7 +426,7 @@ func TestPRView_previewCurrentBranch(t *testing.T) {
426426
})
427427
defer restoreCmd()
428428

429-
output, err := RunCommand(prViewCmd, "pr view -p")
429+
output, err := RunCommand(prViewCmd, "pr view")
430430
if err != nil {
431431
t.Errorf("error running command `pr view`: %v", err)
432432
}
@@ -461,7 +461,7 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
461461
})
462462
defer restoreCmd()
463463

464-
output, err := RunCommand(prViewCmd, "pr view -p")
464+
output, err := RunCommand(prViewCmd, "pr view")
465465
if err != nil {
466466
t.Errorf("error running command `pr view`: %v", err)
467467
}
@@ -481,7 +481,7 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
481481
}
482482
}
483483

484-
func TestPRView_currentBranch(t *testing.T) {
484+
func TestPRView_web_currentBranch(t *testing.T) {
485485
initBlankContext("OWNER/REPO", "blueberries")
486486
http := initFakeHTTP()
487487
http.StubRepoResponse("OWNER", "REPO")
@@ -502,7 +502,7 @@ func TestPRView_currentBranch(t *testing.T) {
502502
})
503503
defer restoreCmd()
504504

505-
output, err := RunCommand(prViewCmd, "pr view")
505+
output, err := RunCommand(prViewCmd, "pr view -w")
506506
if err != nil {
507507
t.Errorf("error running command `pr view`: %v", err)
508508
}
@@ -519,7 +519,7 @@ func TestPRView_currentBranch(t *testing.T) {
519519
}
520520
}
521521

522-
func TestPRView_noResultsForBranch(t *testing.T) {
522+
func TestPRView_web_noResultsForBranch(t *testing.T) {
523523
initBlankContext("OWNER/REPO", "blueberries")
524524
http := initFakeHTTP()
525525
http.StubRepoResponse("OWNER", "REPO")
@@ -540,7 +540,7 @@ func TestPRView_noResultsForBranch(t *testing.T) {
540540
})
541541
defer restoreCmd()
542542

543-
_, err := RunCommand(prViewCmd, "pr view")
543+
_, err := RunCommand(prViewCmd, "pr view -w")
544544
if err == nil || err.Error() != `no open pull requests found for branch "blueberries"` {
545545
t.Errorf("error running command `pr view`: %v", err)
546546
}
@@ -550,7 +550,7 @@ func TestPRView_noResultsForBranch(t *testing.T) {
550550
}
551551
}
552552

553-
func TestPRView_numberArg(t *testing.T) {
553+
func TestPRView_web_numberArg(t *testing.T) {
554554
initBlankContext("OWNER/REPO", "master")
555555
http := initFakeHTTP()
556556
http.StubRepoResponse("OWNER", "REPO")
@@ -568,7 +568,7 @@ func TestPRView_numberArg(t *testing.T) {
568568
})
569569
defer restoreCmd()
570570

571-
output, err := RunCommand(prViewCmd, "pr view 23")
571+
output, err := RunCommand(prViewCmd, "pr view -w 23")
572572
if err != nil {
573573
t.Errorf("error running command `pr view`: %v", err)
574574
}
@@ -582,7 +582,7 @@ func TestPRView_numberArg(t *testing.T) {
582582
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
583583
}
584584

585-
func TestPRView_numberArgWithHash(t *testing.T) {
585+
func TestPRView_web_numberArgWithHash(t *testing.T) {
586586
initBlankContext("OWNER/REPO", "master")
587587
http := initFakeHTTP()
588588
http.StubRepoResponse("OWNER", "REPO")
@@ -600,7 +600,7 @@ func TestPRView_numberArgWithHash(t *testing.T) {
600600
})
601601
defer restoreCmd()
602602

603-
output, err := RunCommand(prViewCmd, "pr view \"#23\"")
603+
output, err := RunCommand(prViewCmd, "pr view -w \"#23\"")
604604
if err != nil {
605605
t.Errorf("error running command `pr view`: %v", err)
606606
}
@@ -614,7 +614,7 @@ func TestPRView_numberArgWithHash(t *testing.T) {
614614
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
615615
}
616616

617-
func TestPRView_urlArg(t *testing.T) {
617+
func TestPRView_web_urlArg(t *testing.T) {
618618
initBlankContext("OWNER/REPO", "master")
619619
http := initFakeHTTP()
620620
http.StubRepoResponse("OWNER", "REPO")
@@ -632,7 +632,7 @@ func TestPRView_urlArg(t *testing.T) {
632632
})
633633
defer restoreCmd()
634634

635-
output, err := RunCommand(prViewCmd, "pr view https://github.com/OWNER/REPO/pull/23/files")
635+
output, err := RunCommand(prViewCmd, "pr view -w https://github.com/OWNER/REPO/pull/23/files")
636636
if err != nil {
637637
t.Errorf("error running command `pr view`: %v", err)
638638
}
@@ -646,7 +646,7 @@ func TestPRView_urlArg(t *testing.T) {
646646
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
647647
}
648648

649-
func TestPRView_branchArg(t *testing.T) {
649+
func TestPRView_web_branchArg(t *testing.T) {
650650
initBlankContext("OWNER/REPO", "master")
651651
http := initFakeHTTP()
652652
http.StubRepoResponse("OWNER", "REPO")
@@ -666,7 +666,7 @@ func TestPRView_branchArg(t *testing.T) {
666666
})
667667
defer restoreCmd()
668668

669-
output, err := RunCommand(prViewCmd, "pr view blueberries")
669+
output, err := RunCommand(prViewCmd, "pr view -w blueberries")
670670
if err != nil {
671671
t.Errorf("error running command `pr view`: %v", err)
672672
}
@@ -680,7 +680,7 @@ func TestPRView_branchArg(t *testing.T) {
680680
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
681681
}
682682

683-
func TestPRView_branchWithOwnerArg(t *testing.T) {
683+
func TestPRView_web_branchWithOwnerArg(t *testing.T) {
684684
initBlankContext("OWNER/REPO", "master")
685685
http := initFakeHTTP()
686686
http.StubRepoResponse("OWNER", "REPO")
@@ -701,7 +701,7 @@ func TestPRView_branchWithOwnerArg(t *testing.T) {
701701
})
702702
defer restoreCmd()
703703

704-
output, err := RunCommand(prViewCmd, "pr view hubot:blueberries")
704+
output, err := RunCommand(prViewCmd, "pr view -w hubot:blueberries")
705705
if err != nil {
706706
t.Errorf("error running command `pr view`: %v", err)
707707
}

0 commit comments

Comments
 (0)