X Tutup
Skip to content

Commit a496549

Browse files
authored
Merge pull request cli#3024 from cli/normalize-pr-commands
Normalize pr command arguments
2 parents 8235140 + 34da597 commit a496549

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

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
},

0 commit comments

Comments
 (0)
X Tutup