MCPcopy Create free account
hub / github.com/docker/docker-agent / LookupByCommand

Method LookupByCommand

pkg/toolinstall/registry.go:231–254  ·  view source on GitHub ↗

LookupByCommand searches for a package providing a binary matching the command name. First checks repo names, then files[].name across all packages.

(ctx context.Context, command string)

Source from the content-addressed store, hash-verified

229// LookupByCommand searches for a package providing a binary matching the command name.
230// First checks repo names, then files[].name across all packages.
231func (r *Registry) LookupByCommand(ctx context.Context, command string) (*Package, error) {
232 index, err := r.fetchIndex(ctx)
233 if err != nil {
234 return nil, fmt.Errorf("fetching registry index: %w", err)
235 }
236
237 // Single pass: prefer repo name match, but track the first file-name match.
238 var fileMatch *Package
239 for i := range index.Packages {
240 p := &index.Packages[i]
241 if p.RepoName == command {
242 return p, nil
243 }
244 if fileMatch == nil && providesCommand(p, command) {
245 fileMatch = p
246 }
247 }
248
249 if fileMatch != nil {
250 return fileMatch, nil
251 }
252
253 return nil, fmt.Errorf("no aqua package found providing command %q", command)
254}
255
256// providesCommand returns true if any of the package's files entries has
257// a binary matching the given command name.

Calls 2

fetchIndexMethod · 0.95
providesCommandFunction · 0.85