MCPcopy
hub / github.com/cli/cli / NewCmdCreate

Function NewCmdCreate

pkg/cmd/gist/create/create.go:42–105  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*CreateOptions) error)

Source from the content-addressed store, hash-verified

40}
41
42func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
43 opts := CreateOptions{
44 IO: f.IOStreams,
45 Config: f.Config,
46 HttpClient: f.HttpClient,
47 Browser: f.Browser,
48 }
49
50 cmd := &cobra.Command{
51 Use: "create [<filename>... | <pattern>... | -]",
52 Short: "Create a new gist",
53 Long: heredoc.Docf(`
54 Create a new GitHub gist with given contents.
55
56 Gists can be created from one or multiple files. Alternatively, pass %[1]s-%[1]s as
57 filename to read from standard input.
58
59 By default, gists are secret; use %[1]s--public%[1]s to make publicly listed ones.
60 `, "`"),
61 Example: heredoc.Doc(`
62 # Publish file 'hello.py' as a public gist
63 $ gh gist create --public hello.py
64
65 # Create a gist with a description
66 $ gh gist create hello.py -d "my Hello-World program in Python"
67
68 # Create a gist containing several files
69 $ gh gist create hello.py world.py cool.txt
70
71 # Create a gist containing several files using patterns
72 $ gh gist create *.md *.txt artifact.*
73
74 # Read from standard input to create a gist
75 $ gh gist create -
76
77 # Create a gist from output piped from another command
78 $ cat cool.txt | gh gist create
79 `),
80 Args: func(cmd *cobra.Command, args []string) error {
81 if len(args) > 0 {
82 return nil
83 }
84 if opts.IO.IsStdinTTY() {
85 return cmdutil.FlagErrorf("no filenames passed and nothing on STDIN")
86 }
87 return nil
88 },
89 Aliases: []string{"new"},
90 RunE: func(c *cobra.Command, args []string) error {
91 opts.Filenames = args
92
93 if runF != nil {
94 return runF(&opts)
95 }
96 return createRun(&opts)
97 },
98 }
99

Callers 1

TestNewCmdCreateFunction · 0.70

Calls 3

FlagErrorfFunction · 0.92
IsStdinTTYMethod · 0.80
createRunFunction · 0.70

Tested by 1

TestNewCmdCreateFunction · 0.56