Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --quiet to machine ls #13898

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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