diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/containers/ps.go | 53 | ||||
-rw-r--r-- | cmd/podman/containers/rm.go | 13 | ||||
-rw-r--r-- | cmd/podman/play/kube.go | 1 | ||||
-rw-r--r-- | cmd/podman/volumes/list.go | 54 |
4 files changed, 59 insertions, 62 deletions
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go index c4c8b60f3..8082a74c2 100644 --- a/cmd/podman/containers/ps.go +++ b/cmd/podman/containers/ps.go @@ -12,7 +12,9 @@ import ( tm "github.com/buger/goterm" "github.com/containers/buildah/pkg/formats" + "github.com/containers/podman/v2/cmd/podman/parse" "github.com/containers/podman/v2/cmd/podman/registry" + "github.com/containers/podman/v2/cmd/podman/report" "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" @@ -176,47 +178,51 @@ func ps(cmd *cobra.Command, args []string) error { return err } } - if listOpts.Format == "json" { + + switch { + case parse.MatchesJSONFormat(listOpts.Format): return jsonOut(listContainers) - } - if listOpts.Quiet { + case listOpts.Quiet: return quietOut(listContainers) } + // Output table Watch > 0 will refresh screen responses := make([]psReporter, 0, len(listContainers)) for _, r := range listContainers { responses = append(responses, psReporter{r}) } - headers, format := createPsOut() - if cmd.Flag("format").Changed { - format = strings.TrimPrefix(listOpts.Format, "table ") - if !strings.HasPrefix(format, "\n") { - format += "\n" - } - } - format = "{{range . }}" + format + "{{end}}" - if !listOpts.Quiet && !cmd.Flag("format").Changed { - format = headers + format + var headers, format string + if cmd.Flags().Changed("format") { + headers = "" + format = report.NormalizeFormat(listOpts.Format) + } else { + headers, format = createPsOut() } + format = headers + "{{range . }}" + format + "{{end}}" + tmpl, err := template.New("listContainers").Parse(format) if err != nil { return err } w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) + defer w.Flush() + if listOpts.Watch > 0 { for { var responses []psReporter tm.Clear() tm.MoveCursor(1, 1) tm.Flush() - listContainers, err := getResponses() - for _, r := range listContainers { - responses = append(responses, psReporter{r}) - } - if err != nil { + + if ctnrs, err := getResponses(); err != nil { return err + } else { + for _, r := range ctnrs { + responses = append(responses, psReporter{r}) + } } + if err := tmpl.Execute(w, responses); err != nil { return err } @@ -232,11 +238,11 @@ func ps(cmd *cobra.Command, args []string) error { if err := tmpl.Execute(w, responses); err != nil { return err } - return w.Flush() } return nil } +// cannot use report.Headers() as it doesn't support structures as fields func createPsOut() (string, string) { var row string if listOpts.Namespace { @@ -257,12 +263,9 @@ func createPsOut() (string, string) { headers += "\tSIZE" row += "\t{{.Size}}" } - if !strings.HasSuffix(headers, "\n") { - headers += "\n" - } - if !strings.HasSuffix(row, "\n") { - row += "\n" - } + + headers = report.NormalizeFormat(headers) + row = report.NormalizeFormat(row) return headers, row } diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go index f8f12234d..a7739b3ba 100644 --- a/cmd/podman/containers/rm.go +++ b/cmd/podman/containers/rm.go @@ -57,13 +57,12 @@ func rmFlags(flags *pflag.FlagSet) { flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all containers") flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing") flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running or unusable container. The default is false") - flags.BoolVar(&rmOptions.Storage, "storage", false, "Remove container from storage library") flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container") flags.StringArrayVarP(&rmOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file") - if registry.IsRemote() { - _ = flags.MarkHidden("ignore") - _ = flags.MarkHidden("cidfile") + if !registry.IsRemote() { + // This option is deprecated, but needs to still exists for backwards compatibility + flags.Bool("storage", false, "Remove container from storage library") _ = flags.MarkHidden("storage") } } @@ -97,12 +96,6 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit var ( errs utils.OutputErrors ) - // Storage conflicts with --all/--latest/--volumes/--cidfile/--ignore - if rmOptions.Storage { - if rmOptions.All || rmOptions.Ignore || rmOptions.Latest || rmOptions.Volumes || rmOptions.CIDFiles != nil { - return errors.Errorf("--storage conflicts with --volumes, --all, --latest, --ignore and --cidfile") - } - } responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions) if err != nil { if setExit { diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go index 54a6d0677..976d720ee 100644 --- a/cmd/podman/play/kube.go +++ b/cmd/podman/play/kube.go @@ -60,6 +60,7 @@ func init() { flags.BoolVar(&kubeOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries") flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)") flags.StringVar(&kubeOptions.SeccompProfileRoot, "seccomp-profile-root", defaultSeccompRoot, "Directory path for seccomp profiles") + flags.StringSliceVar(&kubeOptions.ConfigMaps, "configmap", []string{}, "`Pathname` of a YAML file containing a kubernetes configmap") } _ = flags.MarkHidden("signature-policy") } diff --git a/cmd/podman/volumes/list.go b/cmd/podman/volumes/list.go index d198e51a7..18765a499 100644 --- a/cmd/podman/volumes/list.go +++ b/cmd/podman/volumes/list.go @@ -3,13 +3,14 @@ package volumes import ( "context" "fmt" - "io" "os" "strings" "text/tabwriter" "text/template" + "github.com/containers/podman/v2/cmd/podman/parse" "github.com/containers/podman/v2/cmd/podman/registry" + "github.com/containers/podman/v2/cmd/podman/report" "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/pkg/errors" @@ -55,7 +56,6 @@ func init() { } func list(cmd *cobra.Command, args []string) error { - var w io.Writer = os.Stdout if cliOpts.Quiet && cmd.Flag("format").Changed { return errors.New("quiet and format flags cannot be used together") } @@ -73,40 +73,40 @@ func list(cmd *cobra.Command, args []string) error { if err != nil { return err } - if cliOpts.Format == "json" { - return outputJSON(responses) - } - if len(responses) < 1 { + switch { + case parse.MatchesJSONFormat(cliOpts.Format): + return outputJSON(responses) + case len(responses) < 1: return nil } - // "\t" from the command line is not being recognized as a tab - // replacing the string "\t" to a tab character if the user passes in "\t" - cliOpts.Format = strings.Replace(cliOpts.Format, `\t`, "\t", -1) + return outputTemplate(cmd, responses) +} + +func outputTemplate(cmd *cobra.Command, responses []*entities.VolumeListReport) error { + headers := report.Headers(entities.VolumeListReport{}, map[string]string{ + "Name": "VOLUME NAME", + }) + + row := report.NormalizeFormat(cliOpts.Format) if cliOpts.Quiet { - cliOpts.Format = "{{.Name}}\n" + row = "{{.Name}}\n" } - headers := "DRIVER\tVOLUME NAME\n" - row := cliOpts.Format - if !strings.HasSuffix(cliOpts.Format, "\n") { - row += "\n" - } - format := "{{range . }}" + row + "{{end}}" - if !cliOpts.Quiet && !cmd.Flag("format").Changed { - w = tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0) - format = headers + format - } - tmpl, err := template.New("listVolume").Parse(format) + row = "{{range . }}" + row + "{{end}}" + + tmpl, err := template.New("list volume").Parse(row) if err != nil { return err } - if err := tmpl.Execute(w, responses); err != nil { - return err - } - if flusher, ok := w.(interface{ Flush() error }); ok { - return flusher.Flush() + w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0) + defer w.Flush() + + if !cliOpts.Quiet && !cmd.Flag("format").Changed { + if err := tmpl.Execute(w, headers); err != nil { + return errors.Wrapf(err, "failed to write report column headers") + } } - return nil + return tmpl.Execute(w, responses) } func outputJSON(vols []*entities.VolumeListReport) error { |