|
1 | 1 | package command |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "fmt" |
5 | 6 | "io" |
6 | 7 | "os" |
@@ -45,8 +46,13 @@ A pull request can be supplied as argument in any of the following formats: |
45 | 46 | var prCheckoutCmd = &cobra.Command{ |
46 | 47 | Use: "checkout {<number> | <url> | <branch>}", |
47 | 48 | Short: "Check out a pull request in Git", |
48 | | - Args: cobra.MinimumNArgs(1), |
49 | | - RunE: prCheckout, |
| 49 | + Args: func(cmd *cobra.Command, args []string) error { |
| 50 | + if len(args) < 1 { |
| 51 | + return errors.New("requires a PR number as an argument") |
| 52 | + } |
| 53 | + return nil |
| 54 | + }, |
| 55 | + RunE: prCheckout, |
50 | 56 | } |
51 | 57 | var prListCmd = &cobra.Command{ |
52 | 58 | Use: "list", |
@@ -191,8 +197,8 @@ func prList(cmd *cobra.Command, args []string) error { |
191 | 197 | msg := "There are no open pull requests" |
192 | 198 |
|
193 | 199 | userSetFlags := false |
194 | | - cmd.Flags().VisitAll(func(f *pflag.Flag) { |
195 | | - userSetFlags = f.Changed || userSetFlags |
| 200 | + cmd.Flags().Visit(func(f *pflag.Flag) { |
| 201 | + userSetFlags = true |
196 | 202 | }) |
197 | 203 | if userSetFlags { |
198 | 204 | msg = "No pull requests match your search" |
@@ -263,8 +269,13 @@ func prView(cmd *cobra.Command, args []string) error { |
263 | 269 | } else { |
264 | 270 | pr, err := api.PullRequestForBranch(apiClient, baseRepo, branchWithOwner) |
265 | 271 | if err != nil { |
| 272 | + var notFoundErr *api.NotFoundError |
| 273 | + if errors.As(err, ¬FoundErr) { |
| 274 | + return fmt.Errorf("%s. To open a specific pull request use the pull request's number as an argument", err) |
| 275 | + } |
266 | 276 | return err |
267 | 277 | } |
| 278 | + |
268 | 279 | openURL = pr.URL |
269 | 280 | } |
270 | 281 | } |
|
0 commit comments