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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/auth"
|
"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.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.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() {
|
if !registry.IsRemote() {
|
||||||
certDirFlagName := "cert-dir"
|
certDirFlagName := "cert-dir"
|
||||||
|
@ -160,6 +162,9 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
||||||
if len(searchReport) == 0 {
|
if len(searchReport) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if searchOptions.ReverseOrder {
|
||||||
|
reverseOrder(searchReport)
|
||||||
|
}
|
||||||
|
|
||||||
isJSON := report.IsJSON(searchOptions.Format)
|
isJSON := report.IsJSON(searchOptions.Format)
|
||||||
for i, element := range searchReport {
|
for i, element := range searchReport {
|
||||||
|
@ -241,3 +246,11 @@ ReportLoop:
|
||||||
}
|
}
|
||||||
return entries
|
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*).
|
Do not truncate the output (default *false*).
|
||||||
|
|
||||||
|
#### **--reverse-order**
|
||||||
|
|
||||||
|
List tags in reverse order. Default is false.
|
||||||
|
|
||||||
@@option tls-verify
|
@@option tls-verify
|
||||||
|
|
||||||
## EXAMPLES
|
## EXAMPLES
|
||||||
|
|
|
@ -237,6 +237,8 @@ type ImageSearchOptions struct {
|
||||||
SkipTLSVerify types.OptionalBool
|
SkipTLSVerify types.OptionalBool
|
||||||
// ListTags search the available tags of the repository
|
// ListTags search the available tags of the repository
|
||||||
ListTags bool
|
ListTags bool
|
||||||
|
// List tags either in descending or ascending order
|
||||||
|
ReverseOrder bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageSearchReport is the response from searching images.
|
// ImageSearchReport is the response from searching images.
|
||||||
|
|
|
@ -7,7 +7,9 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
"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() {
|
It("podman search format json list tags", func() {
|
||||||
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", ALPINE})
|
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", ALPINE})
|
||||||
search.WaitWithDefaultTimeout()
|
search.WaitWithDefaultTimeout()
|
||||||
|
|
Loading…
Reference in New Issue