Skip to content

Commit 9d062ed

Browse files
committed
Normalize pr command arguments
1 parent c5af4dd commit 9d062ed

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

pkg/cmd/pr/close/close.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func NewCmdClose(f *cmdutil.Factory, runF func(*CloseOptions) error) *cobra.Comm
3535
}
3636

3737
cmd := &cobra.Command{
38-
Use: "close {<number> | <url> | <branch>}",
38+
Use: "close [<number> | <url> | <branch>]",
3939
Short: "Close a pull request",
40-
Args: cobra.ExactArgs(1),
40+
Args: cobra.MaximumNArgs(1),
4141
RunE: func(cmd *cobra.Command, args []string) error {
4242
// support `-R, --repo` override
4343
opts.BaseRepo = f.BaseRepo

pkg/cmd/pr/comment/comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func NewCmdComment(f *cmdutil.Factory, runF func(*shared.CommentableOptions) err
3030
Example: heredoc.Doc(`
3131
$ gh pr comment 22 --body "This looks great, lets get it deployed."
3232
`),
33+
Args: cobra.MaximumNArgs(1),
3334
PreRunE: func(cmd *cobra.Command, args []string) error {
3435
if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
3536
return &cmdutil.FlagError{Err: errors.New("argument required when using the --repo flag")}

pkg/cmd/pr/comment/comment_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func TestNewCmdComment(t *testing.T) {
3232
},
3333
wantsErr: false,
3434
},
35+
{
36+
name: "two arguments",
37+
input: "1 2",
38+
output: shared.CommentableOptions{},
39+
wantsErr: true,
40+
},
3541
{
3642
name: "pr number",
3743
input: "1",

pkg/cmd/pr/edit/edit.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
4646
}
4747

4848
cmd := &cobra.Command{
49-
Use: "edit {<number> | <url>}",
49+
Use: "edit [<number> | <url> | <branch>]",
5050
Short: "Edit a pull request",
5151
Example: heredoc.Doc(`
5252
$ gh pr edit 23 --title "I found a bug" --body "Nothing works"
@@ -56,12 +56,14 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
5656
$ gh pr edit 23 --add-project "Roadmap" --remove-project v1,v2
5757
$ gh pr edit 23 --milestone "Version 1"
5858
`),
59-
Args: cobra.ExactArgs(1),
59+
Args: cobra.MaximumNArgs(1),
6060
RunE: func(cmd *cobra.Command, args []string) error {
6161
// support `-R, --repo` override
6262
opts.BaseRepo = f.BaseRepo
6363

64-
opts.SelectorArg = args[0]
64+
if len(args) > 0 {
65+
opts.SelectorArg = args[0]
66+
}
6567

6668
flags := cmd.Flags()
6769
if flags.Changed("title") {

pkg/cmd/pr/edit/edit_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ func TestNewCmdEdit(t *testing.T) {
2323
wantsErr bool
2424
}{
2525
{
26-
name: "no argument",
27-
input: "",
26+
name: "no argument",
27+
input: "",
28+
output: EditOptions{
29+
SelectorArg: "",
30+
Interactive: true,
31+
},
32+
wantsErr: false,
33+
},
34+
{
35+
name: "two arguments",
36+
input: "1 2",
2837
output: EditOptions{},
2938
wantsErr: true,
3039
},

pkg/cmd/pr/reopen/reopen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func NewCmdReopen(f *cmdutil.Factory, runF func(*ReopenOptions) error) *cobra.Co
3030
}
3131

3232
cmd := &cobra.Command{
33-
Use: "reopen {<number> | <url> | <branch>}",
33+
Use: "reopen [<number> | <url> | <branch>]",
3434
Short: "Reopen a pull request",
35-
Args: cobra.ExactArgs(1),
35+
Args: cobra.MaximumNArgs(1),
3636
RunE: func(cmd *cobra.Command, args []string) error {
3737
// support `-R, --repo` override
3838
opts.BaseRepo = f.BaseRepo

0 commit comments

Comments
 (0)