diff --git a/pkg/config/registry/package_info.go b/pkg/config/registry/package_info.go index 2a5497380..ba0895de6 100644 --- a/pkg/config/registry/package_info.go +++ b/pkg/config/registry/package_info.go @@ -3,6 +3,7 @@ package registry import ( "fmt" "path" + "strings" "github.com/aquaproj/aqua/pkg/runtime" "github.com/iancoleman/orderedmap" @@ -409,28 +410,34 @@ func (pkgInfo *PackageInfo) GetFiles() []*File { if len(pkgInfo.Files) != 0 { return pkgInfo.Files } - if pkgInfo.HasRepo() { + + if cmdName := pkgInfo.getDefaultCmdName(); cmdName != "" { return []*File{ { - Name: pkgInfo.RepoName, + Name: cmdName, }, } } + return pkgInfo.Files +} + +func (pkgInfo *PackageInfo) getDefaultCmdName() string { + if pkgInfo.HasRepo() { + if pkgInfo.Name == "" { + return pkgInfo.RepoName + } + if i := strings.LastIndex(pkgInfo.Name, "/"); i != -1 { + return pkgInfo.Name[i+1:] + } + return pkgInfo.Name + } if pkgInfo.Type == PkgInfoTypeGoInstall { if pkgInfo.Asset != nil { - return []*File{ - { - Name: *pkgInfo.Asset, - }, - } - } - return []*File{ - { - Name: path.Base(pkgInfo.GetPath()), - }, + return *pkgInfo.Asset } + return path.Base(pkgInfo.GetPath()) } - return pkgInfo.Files + return "" } func (pkgInfo *PackageInfo) SLSASourceURI() string { diff --git a/pkg/config/registry/package_info_test.go b/pkg/config/registry/package_info_test.go index ed3e86d8d..f6546fb5d 100644 --- a/pkg/config/registry/package_info_test.go +++ b/pkg/config/registry/package_info_test.go @@ -207,7 +207,7 @@ func TestPackageInfo_GetReplacements(t *testing.T) { } } -func TestPackageInfo_GetFiles(t *testing.T) { +func TestPackageInfo_GetFiles(t *testing.T) { //nolint:funlen t.Parallel() data := []struct { title string @@ -248,6 +248,20 @@ func TestPackageInfo_GetFiles(t *testing.T) { RepoName: "ci-info", }, }, + { + title: "has name", + exp: []*registry.File{ + { + Name: "cmctl", + }, + }, + pkgInfo: ®istry.PackageInfo{ + Type: "github_release", + RepoOwner: "cert-manager", + RepoName: "cert-manager", + Name: "cert-manager/cert-manager/cmctl", + }, + }, } for _, d := range data { d := d