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

Function parseSource

pkg/cmd/issue/artifact/create/create.go:250–267  ·  view source on GitHub ↗

parseSource reads one file or URL argument. An http:// or https:// argument is always a link, and any `#` stays part of the URL. Like every link, a URL is read with its surrounding whitespace trimmed, which also keeps it on one result line. Any other argument is a file, and a name can follow it afte

(arg string)

Source from the content-addressed store, hash-verified

248// result line. Any other argument is a file, and a name can follow it after
249// `#`, split the way --attach splits its alt text.
250func parseSource(arg string) (source, error) {
251 trimmed := strings.TrimSpace(arg)
252 lower := strings.ToLower(trimmed)
253 if strings.HasPrefix(lower, "http://") || strings.HasPrefix(lower, "https://") {
254 return source{kind: fromURL, arg: trimmed}, nil
255 }
256
257 path, name := attachments.SplitFileArg(arg)
258 // Only --body-file reads standard input, and "-" is how a result line
259 // names it.
260 if path == "-" {
261 return source{}, cmdutil.FlagErrorf("cannot create an artifact from `-`; use `--body-file -` to read standard input")
262 }
263 if path != arg && name == "" {
264 return source{}, cmdutil.FlagErrorf("artifact name after `#` cannot be blank in %q", arg)
265 }
266 return source{kind: fromFile, arg: path, name: name}, nil
267}
268
269// artifact is one artifact ready to create.
270type artifact struct {

Callers 1

NewCmdCreateFunction · 0.85

Calls 2

SplitFileArgFunction · 0.92
FlagErrorfFunction · 0.92

Tested by

no test coverage detected