Skip to content

Commit e3e8647

Browse files
committed
Eliminate package-level flags
1 parent 6aa0c07 commit e3e8647

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

command/pr_create.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15-
var (
16-
_draftF bool
17-
_titleF string
18-
_bodyF string
19-
_baseF string
20-
)
21-
2215
func prCreate(cmd *cobra.Command, _ []string) error {
2316
ctx := contextForCommand(cmd)
2417

@@ -50,7 +43,16 @@ func prCreate(cmd *cobra.Command, _ []string) error {
5043
return fmt.Errorf("was not able to push to remote '%s': %s", remote, err)
5144
}
5245

53-
interactive := _titleF == "" || _bodyF == ""
46+
title, err := cmd.Flags().GetString("title")
47+
if err != nil {
48+
return err
49+
}
50+
body, err := cmd.Flags().GetString("body")
51+
if err != nil {
52+
return err
53+
}
54+
55+
interactive := title == "" || body == ""
5456

5557
inProgress := struct {
5658
Body string
@@ -81,10 +83,10 @@ func prCreate(cmd *cobra.Command, _ []string) error {
8183
}
8284

8385
qs := []*survey.Question{}
84-
if _titleF == "" {
86+
if title == "" {
8587
qs = append(qs, titleQuestion)
8688
}
87-
if _bodyF == "" {
89+
if body == "" {
8890
qs = append(qs, bodyQuestion)
8991
}
9092

@@ -126,16 +128,18 @@ func prCreate(cmd *cobra.Command, _ []string) error {
126128
}
127129
}
128130

129-
title := _titleF
130131
if title == "" {
131132
title = inProgress.Title
132133
}
133-
body := _bodyF
134134
if body == "" {
135135
body = inProgress.Body
136136
}
137-
base := _baseF
137+
base, err := cmd.Flags().GetString("base")
138+
if err != nil {
139+
return err
140+
}
138141
if base == "" {
142+
// TODO: use default branch for the repo
139143
base = "master"
140144
}
141145

@@ -149,10 +153,15 @@ func prCreate(cmd *cobra.Command, _ []string) error {
149153
return fmt.Errorf("could not determine GitHub repo: %s", err)
150154
}
151155

156+
isDraft, err := cmd.Flags().GetBool("draft")
157+
if err != nil {
158+
return err
159+
}
160+
152161
params := map[string]interface{}{
153162
"title": title,
154163
"body": body,
155-
"draft": _draftF,
164+
"draft": isDraft,
156165
"baseRefName": base,
157166
"headRefName": head,
158167
}
@@ -202,13 +211,12 @@ var prCreateCmd = &cobra.Command{
202211
}
203212

204213
func init() {
205-
prCreateCmd.Flags().BoolVarP(&_draftF, "draft", "d", false,
214+
prCreateCmd.Flags().BoolP("draft", "d", false,
206215
"Mark PR as a draft")
207-
prCreateCmd.Flags().StringVarP(&_titleF, "title", "t", "",
216+
prCreateCmd.Flags().StringP("title", "t", "",
208217
"Supply a title. Will prompt for one otherwise.")
209-
prCreateCmd.Flags().StringVarP(&_bodyF, "body", "b", "",
218+
prCreateCmd.Flags().StringP("body", "b", "",
210219
"Supply a body. Will prompt for one otherwise.")
211-
prCreateCmd.Flags().StringVarP(&_baseF, "base", "T", "",
220+
prCreateCmd.Flags().StringP("base", "T", "",
212221
"The branch into which you want your code merged")
213-
214222
}

0 commit comments

Comments
 (0)