Skip to content

Commit

Permalink
Merge pull request #13898 from baude/machinelistquiet
Browse files Browse the repository at this point in the history
Add --quiet to machine ls
  • Loading branch information
openshift-merge-robot authored Apr 18, 2022
2 parents 667dae3 + 99bcd65 commit cc4bc25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions cmd/podman/machine/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
type listFlagType struct {
format string
noHeading bool
quiet bool
}

type machineReporter struct {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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"):
Expand All @@ -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")
}
Expand Down
7 changes: 6 additions & 1 deletion docs/source/markdown/podman-machine-list.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ Print usage statement.

#### **--noheading**

Omit the table headings from the listing of pods.
Omit the table headings from the listing of machines

#### **--quiet**, **-q**

Only print the name of the machine. This also implies no table heading
is printed.

## EXAMPLES

Expand Down

0 comments on commit cc4bc25

Please sign in to comment.