switch defaults for issue view

This commit is contained in:
vilmibm 2020-03-17 17:06:14 -05:00
parent c30b482bf0
commit 00de6b9c09
2 changed files with 81 additions and 81 deletions

View file

@ -39,7 +39,7 @@ func init() {
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
issueCmd.AddCommand(issueViewCmd)
issueViewCmd.Flags().BoolP("preview", "p", false, "Display preview of issue content")
issueViewCmd.Flags().BoolP("web", "w", false, "Open issue in browser")
}
var issueCmd = &cobra.Command{
@ -233,17 +233,17 @@ func issueView(cmd *cobra.Command, args []string) error {
}
openURL := issue.URL
preview, err := cmd.Flags().GetBool("preview")
web, err := cmd.Flags().GetBool("web")
if err != nil {
return err
}
if preview {
out := colorableOut(cmd)
return printIssuePreview(out, issue)
} else {
if web {
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
return utils.OpenInBrowser(openURL)
} else {
out := colorableOut(cmd)
return printIssuePreview(out, issue)
}
}

View file

@ -212,79 +212,79 @@ func TestIssueList_disabledIssues(t *testing.T) {
}
}
func TestIssueView_web(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": { "hasIssuesEnabled": true, "issue": {
"number": 123,
"url": "https://github.com/OWNER/REPO/issues/123"
} } } }
`))
var seenCmd *exec.Cmd
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := RunCommand(issueViewCmd, "issue view -w 123")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
eq(t, output.String(), "")
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/issues/123 in your browser.\n")
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
}
func TestIssueView_web_numberArgWithHash(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": { "hasIssuesEnabled": true, "issue": {
"number": 123,
"url": "https://github.com/OWNER/REPO/issues/123"
} } } }
`))
var seenCmd *exec.Cmd
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := RunCommand(issueViewCmd, "issue view -w \"#123\"")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
eq(t, output.String(), "")
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/issues/123 in your browser.\n")
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
}
func TestIssueView(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": { "hasIssuesEnabled": true, "issue": {
"number": 123,
"url": "https://github.com/OWNER/REPO/issues/123"
} } } }
`))
var seenCmd *exec.Cmd
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := RunCommand(issueViewCmd, "issue view 123")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
eq(t, output.String(), "")
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/issues/123 in your browser.\n")
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
}
func TestIssueView_numberArgWithHash(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": { "hasIssuesEnabled": true, "issue": {
"number": 123,
"url": "https://github.com/OWNER/REPO/issues/123"
} } } }
`))
var seenCmd *exec.Cmd
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := RunCommand(issueViewCmd, "issue view \"#123\"")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
eq(t, output.String(), "")
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/issues/123 in your browser.\n")
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
}
func TestIssueView_preview(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": { "hasIssuesEnabled": true, "issue": {
"number": 123,
@ -305,7 +305,7 @@ func TestIssueView_preview(t *testing.T) {
} } } }
`))
output, err := RunCommand(issueViewCmd, "issue view -p 123")
output, err := RunCommand(issueViewCmd, "issue view 123")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
@ -326,7 +326,7 @@ func TestIssueView_preview(t *testing.T) {
}
}
func TestIssueView_previewWithEmptyBody(t *testing.T) {
func TestIssueView_WithEmptyBody(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -351,7 +351,7 @@ func TestIssueView_previewWithEmptyBody(t *testing.T) {
} } } }
`))
output, err := RunCommand(issueViewCmd, "issue view -p 123")
output, err := RunCommand(issueViewCmd, "issue view 123")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
@ -371,7 +371,7 @@ func TestIssueView_previewWithEmptyBody(t *testing.T) {
}
}
func TestIssueView_notFound(t *testing.T) {
func TestIssueView_web_notFound(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
@ -388,7 +388,7 @@ func TestIssueView_notFound(t *testing.T) {
})
defer restoreCmd()
_, err := RunCommand(issueViewCmd, "issue view 9999")
_, err := RunCommand(issueViewCmd, "issue view -w 9999")
if err == nil || err.Error() != "graphql error: 'Could not resolve to an Issue with the number of 9999.'" {
t.Errorf("error running command `issue view`: %v", err)
}
@ -416,7 +416,7 @@ func TestIssueView_disabledIssues(t *testing.T) {
}
}
func TestIssueView_urlArg(t *testing.T) {
func TestIssueView_web_urlArg(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -435,7 +435,7 @@ func TestIssueView_urlArg(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(issueViewCmd, "issue view https://github.com/OWNER/REPO/issues/123")
output, err := RunCommand(issueViewCmd, "issue view -w https://github.com/OWNER/REPO/issues/123")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}