Allow to search by file

Also make possible to retrieve the artifact when searching for matches
between repositories list. This made possible to show the package list
when calling `luet search`.
This commit is contained in:
Ettore Di Giacinto
2021-02-28 18:42:54 +01:00
parent d84f6b31fd
commit 233429bbeb
7 changed files with 312 additions and 142 deletions

View File

@@ -15,7 +15,11 @@
package pkg
import "github.com/pkg/errors"
import (
"regexp"
"github.com/pkg/errors"
)
func clone(src, dst PackageDatabase) error {
for _, i := range src.World() {
@@ -36,3 +40,29 @@ func copy(src PackageDatabase) (PackageDatabase, error) {
return dst, nil
}
func findPackageByFile(db PackageDatabase, pattern string) (Packages, error) {
var ans []Package
re, err := regexp.Compile(pattern)
if err != nil {
return nil, errors.Wrap(err, "Invalid regex "+pattern+"!")
}
PACKAGE:
for _, pack := range db.World() {
files, err := db.GetPackageFiles(pack)
if err == nil {
for _, f := range files {
if re.MatchString(f) {
ans = append(ans, pack)
continue PACKAGE
}
}
}
}
return Packages(ans), nil
}