| 37 | } |
| 38 | |
| 39 | func NewCmdCopy(f *cmdutil.Factory, runF func(config copyConfig) error) *cobra.Command { |
| 40 | opts := copyOpts{} |
| 41 | copyCmd := &cobra.Command{ |
| 42 | Short: "Copy a project", |
| 43 | Use: "copy [<number>]", |
| 44 | Example: heredoc.Doc(` |
| 45 | # Copy project "1" owned by monalisa to github |
| 46 | $ gh project copy 1 --source-owner monalisa --target-owner github --title "a new project" |
| 47 | `), |
| 48 | Args: cobra.MaximumNArgs(1), |
| 49 | RunE: func(cmd *cobra.Command, args []string) error { |
| 50 | client, err := client.New(f) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | if len(args) == 1 { |
| 56 | num, err := strconv.ParseInt(args[0], 10, 32) |
| 57 | if err != nil { |
| 58 | return cmdutil.FlagErrorf("invalid number: %v", args[0]) |
| 59 | } |
| 60 | opts.number = int32(num) |
| 61 | } |
| 62 | |
| 63 | config := copyConfig{ |
| 64 | io: f.IOStreams, |
| 65 | client: client, |
| 66 | opts: opts, |
| 67 | } |
| 68 | |
| 69 | // allow testing of the command without actually running it |
| 70 | if runF != nil { |
| 71 | return runF(config) |
| 72 | } |
| 73 | return runCopy(config) |
| 74 | }, |
| 75 | } |
| 76 | |
| 77 | copyCmd.Flags().StringVar(&opts.sourceOwner, "source-owner", "", "Login of the source owner. Use \"@me\" for the current user.") |
| 78 | copyCmd.Flags().StringVar(&opts.targetOwner, "target-owner", "", "Login of the target owner. Use \"@me\" for the current user.") |
| 79 | copyCmd.Flags().StringVar(&opts.title, "title", "", "Title for the new project") |
| 80 | copyCmd.Flags().BoolVar(&opts.includeDraftIssues, "drafts", false, "Include draft issues when copying") |
| 81 | cmdutil.AddFormatFlags(copyCmd, &opts.exporter) |
| 82 | |
| 83 | _ = copyCmd.MarkFlagRequired("title") |
| 84 | |
| 85 | return copyCmd |
| 86 | } |
| 87 | |
| 88 | func runCopy(config copyConfig) error { |
| 89 | canPrompt := config.io.CanPrompt() |