MCPcopy
hub / github.com/cli/cli / newCmdClone

Function newCmdClone

pkg/cmd/label/clone.go:28–74  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*cloneOptions) error)

Source from the content-addressed store, hash-verified

26}
27
28func newCmdClone(f *cmdutil.Factory, runF func(*cloneOptions) error) *cobra.Command {
29 opts := cloneOptions{
30 HttpClient: f.HttpClient,
31 IO: f.IOStreams,
32 }
33
34 cmd := &cobra.Command{
35 Use: "clone <source-repository>",
36 Short: "Clones labels from one repository to another",
37 Long: heredoc.Docf(`
38 Clones labels from a source repository to a destination repository on GitHub.
39 By default, the destination repository is the current repository.
40
41 All labels from the source repository will be copied to the destination
42 repository. Labels in the destination repository that are not in the source
43 repository will not be deleted or modified.
44
45 Labels from the source repository that already exist in the destination
46 repository will be skipped. You can overwrite existing labels in the
47 destination repository using the %[1]s--force%[1]s flag.
48 `, "`"),
49 Example: heredoc.Doc(`
50 # Clone and overwrite labels from cli/cli repository into the current repository
51 $ gh label clone cli/cli --force
52
53 # Clone labels from cli/cli repository into octocat/cli repository
54 $ gh label clone cli/cli --repo octocat/cli
55 `),
56 Args: cmdutil.ExactArgs(1, "cannot clone labels: source-repository argument required"),
57 RunE: func(c *cobra.Command, args []string) error {
58 var err error
59 opts.BaseRepo = f.BaseRepo
60 opts.SourceRepo, err = ghrepo.FromFullName(args[0])
61 if err != nil {
62 return err
63 }
64 if runF != nil {
65 return runF(&opts)
66 }
67 return cloneRun(&opts)
68 },
69 }
70
71 cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Overwrite labels in the destination repository")
72
73 return cmd
74}
75
76func cloneRun(opts *cloneOptions) error {
77 httpClient, err := opts.HttpClient()

Callers 2

NewCmdLabelFunction · 0.85
TestNewCmdCloneFunction · 0.85

Calls 3

ExactArgsFunction · 0.92
FromFullNameFunction · 0.92
cloneRunFunction · 0.70

Tested by 1

TestNewCmdCloneFunction · 0.68