| 35 | } |
| 36 | |
| 37 | func NewCmdDevelop(f *cmdutil.Factory, runF func(*DevelopOptions) error) *cobra.Command { |
| 38 | opts := &DevelopOptions{ |
| 39 | IO: f.IOStreams, |
| 40 | HttpClient: f.HttpClient, |
| 41 | GitClient: f.GitClient, |
| 42 | BaseRepo: f.BaseRepo, |
| 43 | Remotes: f.Remotes, |
| 44 | } |
| 45 | |
| 46 | cmd := &cobra.Command{ |
| 47 | Use: "develop {<number> | <url>}", |
| 48 | Short: "Manage linked branches for an issue", |
| 49 | Long: heredoc.Docf(` |
| 50 | Manage linked branches for an issue. |
| 51 | |
| 52 | When using the %[1]s--base%[1]s flag, the new development branch will be created from the specified |
| 53 | remote branch. The new branch will be configured as the base branch for pull requests created using |
| 54 | %[1]sgh pr create%[1]s. |
| 55 | `, "`"), |
| 56 | Example: heredoc.Doc(` |
| 57 | # List branches for issue 123 |
| 58 | $ gh issue develop --list 123 |
| 59 | |
| 60 | # List branches for issue 123 in repo cli/cli |
| 61 | $ gh issue develop --list --repo cli/cli 123 |
| 62 | |
| 63 | # Create a branch for issue 123 based on the my-feature branch |
| 64 | $ gh issue develop 123 --base my-feature |
| 65 | |
| 66 | # Create a branch for issue 123 and check it out |
| 67 | $ gh issue develop 123 --checkout |
| 68 | |
| 69 | # Create a branch in repo monalisa/cli for issue 123 in repo cli/cli |
| 70 | $ gh issue develop 123 --repo cli/cli --branch-repo monalisa/cli |
| 71 | `), |
| 72 | Args: cmdutil.ExactArgs(1, "issue number or url is required"), |
| 73 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 74 | // This is all a hack to not break the deprecated issue-repo flag. |
| 75 | // It will be removed in the near future and this hack can be removed at the same time. |
| 76 | flags := cmd.Flags() |
| 77 | if flags.Changed("issue-repo") { |
| 78 | if flags.Changed("repo") { |
| 79 | if flags.Changed("branch-repo") { |
| 80 | return cmdutil.FlagErrorf("specify only `--repo` and `--branch-repo`") |
| 81 | } |
| 82 | branchRepo, _ := flags.GetString("repo") |
| 83 | _ = flags.Set("branch-repo", branchRepo) |
| 84 | } |
| 85 | repo, _ := flags.GetString("issue-repo") |
| 86 | _ = flags.Set("repo", repo) |
| 87 | } |
| 88 | if cmd.Parent() != nil { |
| 89 | return cmd.Parent().PersistentPreRunE(cmd, args) |
| 90 | } |
| 91 | return nil |
| 92 | }, |
| 93 | RunE: func(cmd *cobra.Command, args []string) error { |
| 94 | issueNumber, baseRepo, err := shared.ParseIssueFromArg(args[0]) |