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

Function ParseArtifactArgs

pkg/cmd/issue/artifact/shared/shared.go:84–107  ·  view source on GitHub ↗

ParseArtifactArgs reads the arguments of a command that names artifacts in either of two forms, { ... | ...}, and returns the issue number, the function that resolves its repository, and the artifact numbers in argument order. args must not be empty, which the c

(args []string, baseRepo func() (ghrepo.Interface, error), issueAlone bool)

Source from the content-addressed store, hash-verified

82// numbers are empty. Without it, a lone argument that isn't an artifact URL
83// names no artifact, which fails with MissingArtifactMessage.
84func ParseArtifactArgs(args []string, baseRepo func() (ghrepo.Interface, error), issueAlone bool) (int, func() (ghrepo.Interface, error), []int, error) {
85 if isArtifactURL(args[0]) {
86 return parseArtifactURLs(args)
87 }
88 if len(args) == 1 && !issueAlone {
89 return 0, nil, nil, errors.New(MissingArtifactMessage)
90 }
91
92 issueNumber, repo, err := ParseIssueArg(args[0], baseRepo)
93 if err != nil {
94 return 0, nil, nil, err
95 }
96 numbers := make([]int, 0, len(args)-1)
97 for _, arg := range args[1:] {
98 number, err := ParseArtifactNumber(arg)
99 if err != nil {
100 return 0, nil, nil, err
101 }
102 if numbers, err = appendNew(numbers, number); err != nil {
103 return 0, nil, nil, err
104 }
105 }
106 return issueNumber, repo, numbers, nil
107}
108
109// ParseArtifactArg is ParseArtifactArgs for a command that takes one
110// artifact, {<issue> <artifact-number> | <artifact-url>}. A second artifact

Callers 4

NewCmdDeleteFunction · 0.92
NewCmdDownloadFunction · 0.92
TestParseArtifactArgsFunction · 0.85
ParseArtifactArgFunction · 0.85

Calls 5

isArtifactURLFunction · 0.85
parseArtifactURLsFunction · 0.85
ParseIssueArgFunction · 0.85
ParseArtifactNumberFunction · 0.85
appendNewFunction · 0.85

Tested by 1

TestParseArtifactArgsFunction · 0.68