summaryrefslogtreecommitdiff
path: root/cmd/podman/machine
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-04-16 08:50:41 -0500
committerBrent Baude <bbaude@redhat.com>2022-04-16 08:54:56 -0500
commit99bcd659593970de4b2fd9c6ba0e3c4423f2788d (patch)
tree0a699a611e80a2050d6bb715988dedbe9b0a4dc1 /cmd/podman/machine
parent25eeaec219ccc49dcb35e098afaed7d7987cbee1 (diff)
downloadpodman-99bcd659593970de4b2fd9c6ba0e3c4423f2788d.tar.gz
podman-99bcd659593970de4b2fd9c6ba0e3c4423f2788d.tar.bz2
podman-99bcd659593970de4b2fd9c6ba0e3c4423f2788d.zip
Add --quiet to machine ls
The podman machine ls command would benefit from a --quiet flag which would only print the machine names without the extra information. It also implies --noheader as well. This can be helpful for scripting with the podman cli. Signed-off-by: Brent Baude <bbaude@redhat.com> [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/machine')
-rw-r--r--cmd/podman/machine/list.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go
index b57d911a8..587e521a3 100644
--- a/cmd/podman/machine/list.go
+++ b/cmd/podman/machine/list.go
@@ -41,6 +41,7 @@ var (
type listFlagType struct {
format string
noHeading bool
+ quiet bool
}
type machineReporter struct {
@@ -70,6 +71,7 @@ func init() {
flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\t{{.CPUs}}\t{{.Memory}}\t{{.DiskSize}}\n", "Format volume output using JSON or a Go template")
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(machineReporter{}))
flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
+ flags.BoolVarP(&listFlag.quiet, "quiet", "q", false, "Show only machine names")
}
func list(cmd *cobra.Command, args []string) error {
@@ -79,6 +81,10 @@ func list(cmd *cobra.Command, args []string) error {
err error
)
+ if listFlag.quiet {
+ listFlag.format = "{{.Name}}\n"
+ }
+
provider := getSystemDefaultProvider()
listResponse, err = provider.List(opts)
if err != nil {
@@ -124,7 +130,10 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
"Memory": "MEMORY",
"DiskSize": "DISK SIZE",
})
-
+ printHeader := !listFlag.noHeading
+ if listFlag.quiet {
+ printHeader = false
+ }
var row string
switch {
case cmd.Flags().Changed("format"):
@@ -146,8 +155,7 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
return err
}
defer w.Flush()
-
- if !listFlag.noHeading {
+ if printHeader {
if err := tmpl.Execute(w, headers); err != nil {
return errors.Wrapf(err, "failed to write report column headers")
}