MCPcopy Create free account
hub / github.com/cli/cli / createRun

Function createRun

pkg/cmd/gist/create/create.go:108–190  ·  view source on GitHub ↗
(opts *CreateOptions)

Source from the content-addressed store, hash-verified

106}
107
108func createRun(opts *CreateOptions) error {
109
110 readFromStdInArg, filenames := cmdutil.Partition(opts.Filenames, func(f string) bool {
111 return f == "-"
112 })
113
114 filenames, err := cmdutil.GlobPaths(filenames)
115 if err != nil {
116 return err
117 }
118
119 filenames = append(filenames, readFromStdInArg...)
120
121 if len(filenames) == 0 {
122 filenames = []string{"-"}
123 }
124
125 files, err := processFiles(opts.IO.In, opts.FilenameOverride, filenames)
126 if err != nil {
127 return fmt.Errorf("failed to collect files for posting: %w", err)
128 }
129
130 errOut := opts.IO.ErrOut
131 cs := opts.IO.ColorScheme()
132 gistName := guessGistName(files)
133
134 processMessage := "Creating gist..."
135 if gistName != "" {
136 if len(files) > 1 {
137 processMessage = "Creating gist with multiple files"
138 } else {
139 processMessage = fmt.Sprintf("Creating gist %s", gistName)
140 }
141 }
142 fmt.Fprintf(errOut, "%s %s\n", cs.Muted("-"), processMessage)
143
144 httpClient, err := opts.HttpClient()
145 if err != nil {
146 return err
147 }
148
149 cfg, err := opts.Config()
150 if err != nil {
151 return err
152 }
153
154 host, _ := cfg.Authentication().DefaultHost()
155
156 opts.IO.StartProgressIndicator()
157 gist, err := createGist(httpClient, host, opts.Description, opts.Public, files)
158 opts.IO.StopProgressIndicator()
159 if err != nil {
160 var httpError api.HTTPError
161 if errors.As(err, &httpError) {
162 if httpError.StatusCode == http.StatusUnprocessableEntity {
163 if detectEmptyFiles(files) {
164 fmt.Fprintf(errOut, "%s Failed to create gist: %s\n", cs.FailureIcon(), "a gist file cannot be blank")
165 return cmdutil.SilentError

Callers 2

Test_createRunFunction · 0.70
NewCmdCreateFunction · 0.70

Calls 15

PartitionFunction · 0.92
GlobPathsFunction · 0.92
DisplayURLFunction · 0.92
processFilesFunction · 0.85
guessGistNameFunction · 0.85
createGistFunction · 0.85
detectEmptyFilesFunction · 0.85
ColorSchemeMethod · 0.80
MutedMethod · 0.80
FailureIconMethod · 0.80
RedMethod · 0.80
GreenMethod · 0.80

Tested by 1

Test_createRunFunction · 0.56