MCPcopy
hub / github.com/cli/cli / createRun

Function createRun

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

Source from the content-addressed store, hash-verified

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