diff --git a/commands/issuable/list/issuable_list.go b/commands/issuable/list/issuable_list.go index 36786c0f..a9b337d1 100644 --- a/commands/issuable/list/issuable_list.go +++ b/commands/issuable/list/issuable_list.go @@ -53,6 +53,7 @@ type ListOptions struct { ListType string TitleQualifier string OutputFormat string + Output string IO *iostreams.IOStreams BaseRepo func() (glrepo.Interface, error) @@ -138,10 +139,12 @@ func NewCmdList(f *cmdutils.Factory, runE func(opts *ListOptions) error, issueTy issueListCmd.Flags().BoolVarP(&opts.All, "all", "A", false, fmt.Sprintf("Get all %ss", issueType)) issueListCmd.Flags().BoolVarP(&opts.Closed, "closed", "c", false, fmt.Sprintf("Get only closed %ss", issueType)) issueListCmd.Flags().BoolVarP(&opts.Confidential, "confidential", "C", false, fmt.Sprintf("Filter by confidential %ss", issueType)) - issueListCmd.Flags().StringVarP(&opts.OutputFormat, "output", "F", "details", "One of 'details', 'ids', 'urls' or 'json'") + issueListCmd.Flags().StringVarP(&opts.OutputFormat, "output-format", "F", "details", "One of 'details', 'ids', 'urls'") + issueListCmd.Flags().StringVarP(&opts.Output, "output", "O", "text", "One of 'text' or 'json'") issueListCmd.Flags().IntVarP(&opts.Page, "page", "p", 1, "Page number") issueListCmd.Flags().IntVarP(&opts.PerPage, "per-page", "P", 30, "Number of items to list per page.") issueListCmd.PersistentFlags().StringP("group", "g", "", "Select a group/subgroup. This option is ignored if a repo argument is set.") + issueListCmd.MarkFlagsMutuallyExclusive("output", "output-format") if issueType == issuable.TypeIssue { issueListCmd.Flags().StringVarP(&opts.IssueType, "issue-type", "t", "", "Filter issue by its type {issue|incident|test_case}") @@ -263,7 +266,7 @@ func listRun(opts *ListOptions) error { title.ListActionType = opts.ListType title.CurrentPageTotal = len(issues) - if opts.OutputFormat == "json" { + if opts.Output == "json" { issueListJSON, _ := json.Marshal(issues) fmt.Fprintln(opts.IO.StdOut, string(issueListJSON)) return nil diff --git a/commands/issuable/list/issuable_list_test.go b/commands/issuable/list/issuable_list_test.go index 125855ec..426dceae 100644 --- a/commands/issuable/list/issuable_list_test.go +++ b/commands/issuable/list/issuable_list_test.go @@ -359,7 +359,7 @@ func TestIssueListJSON(t *testing.T) { fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues", httpmock.NewFileResponse(http.StatusOK, "./testdata/issueListFull.json")) - output, err := runCommand("issue", fakeHTTP, true, "-F json", nil, "") + output, err := runCommand("issue", fakeHTTP, true, "--output json", nil, "") if err != nil { t.Errorf("error running command `issue list -F json`: %v", err) } @@ -378,3 +378,10 @@ func TestIssueListJSON(t *testing.T) { assert.JSONEq(t, expectedOut, output.String()) assert.Empty(t, output.Stderr()) } + +func TestIssueListMutualOutputFlags(t *testing.T) { + _, err := runCommand("issue", nil, true, "--output json --output-format ids", nil, "") + + assert.NotNil(t, err) + assert.EqualError(t, err, "if any flags in the group [output output-format] are set none of the others can be; [output output-format] were all set") +} diff --git a/docs/source/incident/list.md b/docs/source/incident/list.md index 01b35260..d1442501 100644 --- a/docs/source/incident/list.md +++ b/docs/source/incident/list.md @@ -48,7 +48,8 @@ glab incident list --milestone release-2.0.0 --opened --not-assignee strings Filter incident by not being assigneed to --not-author strings Filter by not being by author(s) --not-label strings Filter incident by lack of label - -F, --output string One of 'details', 'ids', 'urls' or 'json' (default "details") + -O, --output string One of 'text' or 'json' (default "text") + -F, --output-format string One of 'details', 'ids', 'urls' (default "details") -p, --page int Page number (default 1) -P, --per-page int Number of items to list per page. (default 30) -R, --repo OWNER/REPO Select another repository using the OWNER/REPO or `GROUP/NAMESPACE/REPO` format or full URL or git URL diff --git a/docs/source/issue/list.md b/docs/source/issue/list.md index 2682e55d..53c000dd 100644 --- a/docs/source/issue/list.md +++ b/docs/source/issue/list.md @@ -49,7 +49,8 @@ glab issue list --milestone release-2.0.0 --opened --not-assignee strings Filter issue by not being assigneed to --not-author strings Filter by not being by author(s) --not-label strings Filter issue by lack of label - -F, --output string One of 'details', 'ids', 'urls' or 'json' (default "details") + -O, --output string One of 'text' or 'json' (default "text") + -F, --output-format string One of 'details', 'ids', 'urls' (default "details") -p, --page int Page number (default 1) -P, --per-page int Number of items to list per page. (default 30) -R, --repo OWNER/REPO Select another repository using the OWNER/REPO or `GROUP/NAMESPACE/REPO` format or full URL or git URL