MCPcopy Create free account
hub / github.com/CrowdStrike/perseus / parseModuleArg

Function parseModuleArg

findpath.go:153–178  ·  view source on GitHub ↗

parseModuleArg parses the provided string as a Go module path, optionally with a version, and returns the parsed result. If no version is specified, the highest known version is used.

(ctx context.Context, arg string, client perseusapiconnect.PerseusServiceClient, findLatest bool, status func(string))

Source from the content-addressed store, hash-verified

151// parseModuleArg parses the provided string as a Go module path, optionally with a version, and returns
152// the parsed result. If no version is specified, the highest known version is used.
153func parseModuleArg(ctx context.Context, arg string, client perseusapiconnect.PerseusServiceClient, findLatest bool, status func(string)) (module.Version, error) {
154 defer status("")
155 var m module.Version
156 toks := strings.Split(arg, "@")
157 switch len(toks) {
158 case 1:
159 m.Path = toks[0]
160 case 2:
161 m.Path = toks[0]
162 m.Version = toks[1]
163 default:
164 return module.Version{}, fmt.Errorf("invalid 'from' module path/version %q", arg)
165 }
166 if err := module.CheckPath(m.Path); err != nil {
167 return module.Version{}, fmt.Errorf("the specified module name %q is invalid: %w", m, err)
168 }
169 if m.Version == "" && findLatest {
170 status("determining current version for " + m.String())
171 v, err := lookupLatestModuleVersion(ctx, client, m.Path)
172 if err != nil {
173 return module.Version{}, fmt.Errorf("unable to determine the current version for %q: %w", m.Path, err)
174 }
175 m.Version = v
176 }
177 return m, nil
178}

Callers 1

runFindPathsCommandFunction · 0.85

Calls 2

StringMethod · 0.45

Tested by

no test coverage detected