lookupPackage resolves the aqua package for a command. If versionRef is provided (e.g. "owner/repo@v1.0"), it parses the reference and looks up by name. Otherwise, it searches by command name. Returns the package, the explicit version (if any), and any error.
(ctx context.Context, registry *Registry, command, versionRef string)
| 180 | // and looks up by name. Otherwise, it searches by command name. |
| 181 | // Returns the package, the explicit version (if any), and any error. |
| 182 | func lookupPackage(ctx context.Context, registry *Registry, command, versionRef string) (*Package, string, error) { |
| 183 | if versionRef == "" { |
| 184 | pkg, err := registry.LookupByCommand(ctx, command) |
| 185 | if err != nil { |
| 186 | return nil, "", fmt.Errorf("looking up command %q in aqua registry: %w", command, err) |
| 187 | } |
| 188 | return pkg, "", nil |
| 189 | } |
| 190 | |
| 191 | owner, repo, version, err := parseAquaRef(versionRef) |
| 192 | if err != nil { |
| 193 | return nil, "", fmt.Errorf("parsing aqua reference: %w", err) |
| 194 | } |
| 195 | |
| 196 | pkg, err := registry.LookupByName(ctx, owner+"/"+repo) |
| 197 | if err != nil { |
| 198 | return nil, "", fmt.Errorf("looking up aqua package %s/%s: %w", owner, repo, err) |
| 199 | } |
| 200 | |
| 201 | return pkg, version, nil |
| 202 | } |
| 203 | |
| 204 | // resolveVersion determines the latest version for a package. |
| 205 | func resolveVersion(ctx context.Context, registry *Registry, pkg *Package) (string, error) { |
no test coverage detected