MCPcopy Index your code
hub / github.com/cli/cli / NewCmdClone

Function NewCmdClone

pkg/cmd/gist/clone/clone.go:30–73  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*CloneOptions) error)

Source from the content-addressed store, hash-verified

28}
29
30func NewCmdClone(f *cmdutil.Factory, runF func(*CloneOptions) error) *cobra.Command {
31 opts := &CloneOptions{
32 IO: f.IOStreams,
33 HttpClient: f.HttpClient,
34 GitClient: f.GitClient,
35 Config: f.Config,
36 }
37
38 cmd := &cobra.Command{
39 DisableFlagsInUseLine: true,
40
41 Use: "clone <gist> [<directory>] [-- <gitflags>...]",
42 Args: cmdutil.MinimumArgs(1, "cannot clone: gist argument required"),
43 Short: "Clone a gist locally",
44 Long: heredoc.Docf(`
45 Clone a GitHub gist locally.
46
47 A gist can be supplied as argument in either of the following formats:
48 - by ID, e.g. %[1]s5b0e0062eb8e9654adad7bb1d81cc75f%[1]s
49 - by URL, e.g. %[1]shttps://gist.github.com/OWNER/5b0e0062eb8e9654adad7bb1d81cc75f%[1]s
50
51 Pass additional %[1]sgit clone%[1]s flags by listing them after %[1]s--%[1]s.
52 `, "`"),
53 RunE: func(cmd *cobra.Command, args []string) error {
54 opts.Gist = args[0]
55 opts.GitArgs = args[1:]
56
57 if runF != nil {
58 return runF(opts)
59 }
60
61 return cloneRun(opts)
62 },
63 }
64
65 cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
66 if err == pflag.ErrHelp {
67 return err
68 }
69 return cmdutil.FlagErrorf("%w\nSeparate git clone flags with '--'.", err)
70 })
71
72 return cmd
73}
74
75func cloneRun(opts *CloneOptions) error {
76 gistURL := opts.Gist

Callers 1

runCloneCommandFunction · 0.70

Calls 3

MinimumArgsFunction · 0.92
FlagErrorfFunction · 0.92
cloneRunFunction · 0.70

Tested by 1

runCloneCommandFunction · 0.56