diff --git a/command/config.go b/command/config.go index 7e2a541f7..e27580bd9 100644 --- a/command/config.go +++ b/command/config.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "github.com/spf13/cobra" ) @@ -21,23 +22,21 @@ func init() { var configCmd = &cobra.Command{ Use: "config", - Short: "Set and get gh settings", - Long: `Get and set key/value strings. + Short: "Manage configuration for gh", + Long: `Display or change configuration settings for gh. Current respected settings: -- git_protocol: https or ssh. Default is https. +- git_protocol: "https" or "ssh". Default is "https". - editor: if unset, defaults to environment variables. `, } var configGetCmd = &cobra.Command{ Use: "get ", - Short: "Prints the value of a given configuration key", - Long: `Get the value for a given configuration key. - -Examples: - $ gh config get git_protocol - https + Short: "Print the value of a given configuration key", + Example: ` + $ gh config get git_protocol + https `, Args: cobra.ExactArgs(1), RunE: configGet, @@ -45,11 +44,9 @@ Examples: var configSetCmd = &cobra.Command{ Use: "set ", - Short: "Updates configuration with the value of a given key", - Long: `Update the configuration by setting a key to a value. - -Examples: - $ gh config set editor vim + Short: "Update configuration with a value for the given key", + Example: ` + $ gh config set editor vim `, Args: cobra.ExactArgs(2), RunE: configSet, diff --git a/command/issue.go b/command/issue.go index 8a68e2652..526d02871 100644 --- a/command/issue.go +++ b/command/issue.go @@ -132,6 +132,9 @@ func issueList(cmd *cobra.Command, args []string) error { if err != nil { return err } + if limit <= 0 { + return fmt.Errorf("invalid limit: %v", limit) + } author, err := cmd.Flags().GetString("author") if err != nil { @@ -245,11 +248,9 @@ func issueView(cmd *cobra.Command, args []string) error { 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) } - + out := colorableOut(cmd) + return printIssuePreview(out, issue) } func issueStateTitleWithColor(state string) string { diff --git a/command/issue_test.go b/command/issue_test.go index a612cfab4..418de25d3 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -181,6 +181,18 @@ No issues match your search in OWNER/REPO eq(t, reqBody.Variables.Author, "foo") } +func TestIssueList_withInvalidLimitFlag(t *testing.T) { + initBlankContext("", "OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + _, err := RunCommand("issue list --limit=0") + + if err == nil || err.Error() != "invalid limit: 0" { + t.Errorf("error running command `issue list`: %v", err) + } +} + func TestIssueList_nullAssigneeLabels(t *testing.T) { initBlankContext("", "OWNER/REPO", "master") http := initFakeHTTP() diff --git a/command/pr.go b/command/pr.go index adf8347ab..c5fc1ae7b 100644 --- a/command/pr.go +++ b/command/pr.go @@ -195,6 +195,10 @@ func prList(cmd *cobra.Command, args []string) error { if err != nil { return err } + if limit <= 0 { + return fmt.Errorf("invalid limit: %v", limit) + } + state, err := cmd.Flags().GetString("state") if err != nil { return err @@ -328,10 +332,9 @@ func prView(cmd *cobra.Command, args []string) error { if web { fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL) return utils.OpenInBrowser(openURL) - } else { - out := colorableOut(cmd) - return printPrPreview(out, pr) } + out := colorableOut(cmd) + return printPrPreview(out, pr) } func prClose(cmd *cobra.Command, args []string) error { diff --git a/command/pr_test.go b/command/pr_test.go index a11c60820..4c31198b0 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -437,6 +437,17 @@ func TestPRList_filteringAssigneeLabels(t *testing.T) { } } +func TestPRList_withInvalidLimitFlag(t *testing.T) { + initBlankContext("", "OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + _, err := RunCommand(`pr list --limit=0`) + if err == nil && err.Error() != "invalid limit: 0" { + t.Errorf("error running command `issue list`: %v", err) + } +} + func TestPRView_Preview(t *testing.T) { tests := map[string]struct { ownerRepo string diff --git a/command/title_body_survey.go b/command/title_body_survey.go index d6fe11bbf..1dcf3c668 100644 --- a/command/title_body_survey.go +++ b/command/title_body_survey.go @@ -371,10 +371,8 @@ func titleBodySurvey(cmd *cobra.Command, issueState *issueMetadataState, apiClie issueState.Assignees = values.Assignees issueState.Labels = values.Labels issueState.Projects = values.Projects - issueState.Milestones = []string{values.Milestone} - - if len(issueState.Milestones) > 0 && issueState.Milestones[0] == noMilestone { - issueState.Milestones = issueState.Milestones[0:0] + if values.Milestone != "" && values.Milestone != noMilestone { + issueState.Milestones = []string{values.Milestone} } allowPreview = !issueState.HasMetadata()