From 3b9046a170119c9d3e2975f03587776842c126ec Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Wed, 27 Jun 2018 13:37:56 -0400 Subject: Remove the --registry flag from podman search Instead of setting the --registry flag to search a single registry, prefix the registry before the image name in the input, an example is `podman search registry.fedoraproject.org/fedora` and this will search for the fedora image in only registry.fedoraproject.org. Signed-off-by: umohnani8 Closes: #1011 Approved by: rhatdan --- cmd/podman/search.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/search.go b/cmd/podman/search.go index 064badec8..15dc1df11 100644 --- a/cmd/podman/search.go +++ b/cmd/podman/search.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/containers/image/docker" + "github.com/docker/distribution/reference" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/formats" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" @@ -43,10 +44,6 @@ var ( Name: "no-trunc", Usage: "do not truncate the output", }, - cli.StringSliceFlag{ - Name: "registry", - Usage: "specific registry to search", - }, cli.BoolTFlag{ Name: "tls-verify", Usage: "require HTTPS and verify certificates when contacting registries (default: true)", @@ -98,6 +95,15 @@ func searchCmd(c *cli.Context) error { } term := args[0] + // Check if search term has a registry in it + registry, err := getRegistry(term) + if err != nil { + return errors.Wrapf(err, "error getting registry from %q", term) + } + if registry != "" { + term = term[len(registry)+1:] + } + if err := validateFlags(c, searchFlags); err != nil { return err } @@ -116,7 +122,7 @@ func searchCmd(c *cli.Context) error { filter: c.StringSlice("filter"), authfile: c.String("authfile"), } - regAndSkipTLS, err := getRegistriesAndSkipTLS(c) + regAndSkipTLS, err := getRegistriesAndSkipTLS(c, registry) if err != nil { return err } @@ -158,7 +164,7 @@ func (s *searchParams) headerMap() map[string]string { } // A function for finding which registries can skip TLS -func getRegistriesAndSkipTLS(c *cli.Context) (map[string]bool, error) { +func getRegistriesAndSkipTLS(c *cli.Context, registry string) (map[string]bool, error) { // Variables for setting up Registry and TLSVerify tlsVerify := c.BoolT("tls-verify") forceSecure := false @@ -168,8 +174,8 @@ func getRegistriesAndSkipTLS(c *cli.Context) (map[string]bool, error) { } var registries []string - if len(c.StringSlice("registry")) > 0 { - registries = c.StringSlice("registry") + if registry != "" { + registries = append(registries, registry) } else { var err error registries, err = sysreg.GetRegistries() @@ -343,3 +349,11 @@ func matchesOfficialFilter(filter searchFilterParams, result docker.SearchResult } return true } + +func getRegistry(image string) (string, error) { + imgRef, err := reference.Parse(image) + if err != nil { + return "", err + } + return reference.Domain(imgRef.(reference.Named)), nil +} -- cgit v1.2.3-54-g00ecf