autocomplete podman search --filter

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2022-05-24 10:35:36 +02:00
parent 8af98b342d
commit d924c46dae
35 changed files with 377 additions and 156 deletions

View File

@ -0,0 +1,13 @@
package define
const (
// SearchFilterAutomated is the key for filtering images by their automated attribute.
SearchFilterAutomated = "is-automated"
// SearchFilterOfficial is the key for filtering images by their official attribute.
SearchFilterOfficial = "is-official"
// SearchFilterStars is the key for filtering images by stars.
SearchFilterStars = "stars"
)
// SearchFilters includes all supported search filters.
var SearchFilters = []string{SearchFilterAutomated, SearchFilterOfficial, SearchFilterStars}

View File

@ -114,6 +114,11 @@ func (r *Runtime) loadMultiImageDockerArchive(ctx context.Context, ref types.Ima
if err != nil {
return nil, err
}
defer func() {
if err := reader.Close(); err != nil {
logrus.Errorf("Closing reader of docker archive: %v", err)
}
}()
refLists, err := reader.List()
if err != nil {

View File

@ -315,6 +315,11 @@ func (r *Runtime) copyFromDockerArchive(ctx context.Context, ref types.ImageRefe
if err != nil {
return nil, err
}
defer func() {
if err := reader.Close(); err != nil {
logrus.Errorf("Closing reader of docker archive: %v", err)
}
}()
return r.copyFromDockerArchiveReaderReference(ctx, reader, readerRef, options)
}

View File

@ -7,6 +7,7 @@ import (
"strings"
"sync"
"github.com/containers/common/libimage/define"
registryTransport "github.com/containers/image/v5/docker"
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/image/v5/transports/alltransports"
@ -81,22 +82,22 @@ func ParseSearchFilter(filter []string) (*SearchFilter, error) {
for _, f := range filter {
arr := strings.SplitN(f, "=", 2)
switch arr[0] {
case "stars":
case define.SearchFilterStars:
if len(arr) < 2 {
return nil, errors.Errorf("invalid `stars` filter %q, should be stars=<value>", filter)
return nil, errors.Errorf("invalid filter %q, should be stars=<value>", filter)
}
stars, err := strconv.Atoi(arr[1])
if err != nil {
return nil, errors.Wrapf(err, "incorrect value type for stars filter")
}
sFilter.Stars = stars
case "is-automated":
case define.SearchFilterAutomated:
if len(arr) == 2 && arr[1] == "false" {
sFilter.IsAutomated = types.OptionalBoolFalse
} else {
sFilter.IsAutomated = types.OptionalBoolTrue
}
case "is-official":
case define.SearchFilterOfficial:
if len(arr) == 2 && arr[1] == "false" {
sFilter.IsOfficial = types.OptionalBoolFalse
} else {