mirror of https://github.com/containers/podman.git
Merge f7199498bb
into dfd205fa24
This commit is contained in:
commit
c796ee1275
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/auth"
|
||||
|
@ -108,6 +109,7 @@ func searchFlags(cmd *cobra.Command) {
|
|||
|
||||
flags.BoolVar(&searchOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
|
||||
flags.BoolVar(&searchOptions.ListTags, "list-tags", false, "List the tags of the input registry")
|
||||
flags.BoolVar(&searchOptions.ReverseOrder, "reverse-order", false, "List tags either in descending or ascending order")
|
||||
|
||||
if !registry.IsRemote() {
|
||||
certDirFlagName := "cert-dir"
|
||||
|
@ -160,6 +162,9 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
|||
if len(searchReport) == 0 {
|
||||
return nil
|
||||
}
|
||||
if searchOptions.ReverseOrder {
|
||||
reverseOrder(searchReport)
|
||||
}
|
||||
|
||||
isJSON := report.IsJSON(searchOptions.Format)
|
||||
for i, element := range searchReport {
|
||||
|
@ -241,3 +246,11 @@ ReportLoop:
|
|||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// Reverse tags order
|
||||
func reverseOrder(report []entities.ImageSearchReport) []entities.ImageSearchReport {
|
||||
slices.SortFunc(report, func(a, b entities.ImageSearchReport) int {
|
||||
return -1 * strings.Compare(strings.ToLower(a.Tag), strings.ToLower(b.Tag))
|
||||
})
|
||||
return report
|
||||
}
|
||||
|
|
|
@ -91,6 +91,10 @@ The result contains the Image name and its tag, one line for every tag associate
|
|||
|
||||
Do not truncate the output (default *false*).
|
||||
|
||||
#### **--reverse-order**
|
||||
|
||||
List tags in reverse order. Default is false.
|
||||
|
||||
@@option tls-verify
|
||||
|
||||
## EXAMPLES
|
||||
|
|
|
@ -237,6 +237,8 @@ type ImageSearchOptions struct {
|
|||
SkipTLSVerify types.OptionalBool
|
||||
// ListTags search the available tags of the repository
|
||||
ListTags bool
|
||||
// List tags either in descending or ascending order
|
||||
ReverseOrder bool
|
||||
}
|
||||
|
||||
// ImageSearchReport is the response from searching images.
|
||||
|
|
|
@ -7,7 +7,9 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
|
@ -101,6 +103,26 @@ registries = []`
|
|||
}
|
||||
})
|
||||
|
||||
It("podman search list tags in reverse order", func() {
|
||||
searchAscending := podmanTest.Podman([]string{"search", "--list-tags", ALPINE})
|
||||
searchDecending := podmanTest.Podman([]string{"search", "--list-tags", "--reverse-order", ALPINE})
|
||||
searchAscending.WaitWithDefaultTimeout()
|
||||
searchDecending.WaitWithDefaultTimeout()
|
||||
Expect(searchAscending).Should(ExitCleanly())
|
||||
Expect(searchDecending).Should(ExitCleanly())
|
||||
|
||||
// Removed headers
|
||||
ascendingReport := searchAscending.OutputToStringArray()[1:]
|
||||
descendingReport := searchDecending.OutputToStringArray()[1:]
|
||||
|
||||
// Reverse ascending tags list
|
||||
slices.SortFunc(ascendingReport, func(a, b string) int {
|
||||
return -1 * strings.Compare(strings.ToLower(a), strings.ToLower(b))
|
||||
})
|
||||
|
||||
Expect(ascendingReport).Should(Equal(descendingReport))
|
||||
})
|
||||
|
||||
It("podman search format json list tags", func() {
|
||||
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", ALPINE})
|
||||
search.WaitWithDefaultTimeout()
|
||||
|
|
Loading…
Reference in New Issue