diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/common/create.go | 5 | ||||
-rw-r--r-- | cmd/podman/containers/prune.go | 4 | ||||
-rw-r--r-- | cmd/podman/images/search.go | 47 | ||||
-rw-r--r-- | cmd/podman/play/kube.go | 10 | ||||
-rw-r--r-- | cmd/podman/pods/inspect.go | 5 | ||||
-rw-r--r-- | cmd/podman/pods/prune.go | 2 | ||||
-rw-r--r-- | cmd/podman/pods/rm.go | 4 | ||||
-rw-r--r-- | cmd/podman/system/prune.go | 4 | ||||
-rw-r--r-- | cmd/podman/system/service.go | 2 |
9 files changed, 58 insertions, 25 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 24703eda2..280175f95 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -1,7 +1,6 @@ package common import ( - "fmt" "os" "github.com/containers/common/pkg/auth" @@ -181,7 +180,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { createFlags.StringSliceVar( &cf.Devices, deviceFlagName, devices(), - fmt.Sprintf("Add a host device to the container"), + "Add a host device to the container", ) _ = cmd.RegisterFlagCompletionFunc(deviceFlagName, completion.AutocompleteDefault) @@ -359,7 +358,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { &cf.InitPath, initPathFlagName, initPath(), // Do not use the Value field for setting the default value to determine user input (i.e., non-empty string) - fmt.Sprintf("Path to the container-init binary"), + "Path to the container-init binary", ) _ = cmd.RegisterFlagCompletionFunc(initPathFlagName, completion.AutocompleteDefault) diff --git a/cmd/podman/containers/prune.go b/cmd/podman/containers/prune.go index d3842778b..50731dd21 100644 --- a/cmd/podman/containers/prune.go +++ b/cmd/podman/containers/prune.go @@ -18,9 +18,9 @@ import ( ) var ( - pruneDescription = fmt.Sprintf(`podman container prune + pruneDescription = `podman container prune - Removes all non running containers`) + Removes all non running containers` pruneCommand = &cobra.Command{ Use: "prune [options]", Short: "Remove all non running containers", diff --git a/cmd/podman/images/search.go b/cmd/podman/images/search.go index c2ef7d767..c8ea4b04a 100644 --- a/cmd/podman/images/search.go +++ b/cmd/podman/images/search.go @@ -26,6 +26,12 @@ type searchOptionsWrapper struct { Format string // For go templating } +// listEntryTag is a utility structure used for json serialization. +type listEntryTag struct { + Name string + Tags []string +} + var ( searchOptions = searchOptionsWrapper{} searchDescription = `Search registries for a given image. Can search all the default registries or a specific registry. @@ -149,14 +155,13 @@ func imageSearch(cmd *cobra.Command, args []string) error { if len(searchOptions.Filters) != 0 { return errors.Errorf("filters are not applicable to list tags result") } + if report.IsJSON(searchOptions.Format) { + listTagsEntries := buildListTagsJson(searchReport) + return printJson(listTagsEntries) + } row = "{{.Name}}\t{{.Tag}}\n" case report.IsJSON(searchOptions.Format): - prettyJSON, err := json.MarshalIndent(searchReport, "", " ") - if err != nil { - return err - } - fmt.Println(string(prettyJSON)) - return nil + return printJson(searchReport) case cmd.Flags().Changed("format"): renderHeaders = parse.HasTable(searchOptions.Format) row = report.NormalizeFormat(searchOptions.Format) @@ -180,3 +185,33 @@ func imageSearch(cmd *cobra.Command, args []string) error { return tmpl.Execute(w, searchReport) } + +func printJson(v interface{}) error { + prettyJSON, err := json.MarshalIndent(v, "", " ") + if err != nil { + return err + } + fmt.Println(string(prettyJSON)) + return nil +} + +func buildListTagsJson(searchReport []entities.ImageSearchReport) []listEntryTag { + entries := []listEntryTag{} + +ReportLoop: + for _, report := range searchReport { + for idx, entry := range entries { + if entry.Name == report.Name { + entries[idx].Tags = append(entries[idx].Tags, report.Tag) + continue ReportLoop + } + } + newElem := listEntryTag{ + report.Name, + []string{report.Tag}, + } + + entries = append(entries, newElem) + } + return entries +} diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go index 1f54db203..4c44fa30f 100644 --- a/cmd/podman/play/kube.go +++ b/cmd/podman/play/kube.go @@ -127,23 +127,23 @@ func kube(cmd *cobra.Command, args []string) error { for _, pod := range report.Pods { for _, l := range pod.Logs { - fmt.Fprintf(os.Stderr, l) + fmt.Fprint(os.Stderr, l) } } ctrsFailed := 0 for _, pod := range report.Pods { - fmt.Printf("Pod:\n") + fmt.Println("Pod:") fmt.Println(pod.ID) switch len(pod.Containers) { case 0: continue case 1: - fmt.Printf("Container:\n") + fmt.Println("Container:") default: - fmt.Printf("Containers:\n") + fmt.Println("Containers:") } for _, ctr := range pod.Containers { fmt.Println(ctr) @@ -154,7 +154,7 @@ func kube(cmd *cobra.Command, args []string) error { fmt.Println() } for _, err := range pod.ContainerErrors { - fmt.Fprintf(os.Stderr, err+"\n") + fmt.Fprintln(os.Stderr, err) } // Empty line for space for next block fmt.Println() diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go index 091094ff6..e809be0c9 100644 --- a/cmd/podman/pods/inspect.go +++ b/cmd/podman/pods/inspect.go @@ -2,7 +2,6 @@ package pods import ( "context" - "fmt" "os" "text/tabwriter" "text/template" @@ -21,9 +20,9 @@ var ( ) var ( - inspectDescription = fmt.Sprintf(`Display the configuration for a pod by name or id + inspectDescription = `Display the configuration for a pod by name or id - By default, this will render all results in a JSON array.`) + By default, this will render all results in a JSON array.` inspectCmd = &cobra.Command{ Use: "inspect [options] POD [POD...]", diff --git a/cmd/podman/pods/prune.go b/cmd/podman/pods/prune.go index 965c36398..a040a21b6 100644 --- a/cmd/podman/pods/prune.go +++ b/cmd/podman/pods/prune.go @@ -20,7 +20,7 @@ var ( ) var ( - pruneDescription = fmt.Sprintf(`podman pod prune Removes all exited pods`) + pruneDescription = `podman pod prune Removes all exited pods` pruneCommand = &cobra.Command{ Use: "prune [options]", diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go index ff238aa20..109f18b78 100644 --- a/cmd/podman/pods/rm.go +++ b/cmd/podman/pods/rm.go @@ -25,9 +25,9 @@ type podRmOptionsWrapper struct { var ( rmOptions = podRmOptionsWrapper{} - podRmDescription = fmt.Sprintf(`podman rm will remove one or more stopped pods and their containers from the host. + podRmDescription = `podman rm will remove one or more stopped pods and their containers from the host. - The pod name or ID can be used. A pod with containers will not be removed without --force. If --force is specified, all containers will be stopped, then removed.`) + The pod name or ID can be used. A pod with containers will not be removed without --force. If --force is specified, all containers will be stopped, then removed.` rmCommand = &cobra.Command{ Use: "rm [options] POD [POD...]", Short: "Remove one or more pods", diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go index 87bb947ed..5e96a654a 100644 --- a/cmd/podman/system/prune.go +++ b/cmd/podman/system/prune.go @@ -20,11 +20,11 @@ import ( var ( pruneOptions = entities.SystemPruneOptions{} filters []string - pruneDescription = fmt.Sprintf(` + pruneDescription = ` podman system prune Remove unused data -`) +` pruneCommand = &cobra.Command{ Use: "prune [options]", diff --git a/cmd/podman/system/service.go b/cmd/podman/system/service.go index f8bdbfa10..f5760e172 100644 --- a/cmd/podman/system/service.go +++ b/cmd/podman/system/service.go @@ -80,7 +80,7 @@ func service(cmd *cobra.Command, args []string) error { } // socket activation uses a unix:// socket in the shipped unit files but apiURI is coded as "" at this layer. - if "unix" == uri.Scheme && !registry.IsRemote() { + if uri.Scheme == "unix" && !registry.IsRemote() { if err := syscall.Unlink(uri.Path); err != nil && !os.IsNotExist(err) { return err } |