aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2022-08-19 16:38:49 -0400
committerAshley Cui <acui@redhat.com>2022-08-22 09:13:00 -0400
commiteee0ec97e8eb7436208b7852e7e9ee5974384395 (patch)
treeeb66a474eb9194049859bf59e463fd079b9dd045 /cmd
parent351028b1ac87851fc084b8b5e09eb80660e6bb5a (diff)
downloadpodman-eee0ec97e8eb7436208b7852e7e9ee5974384395.tar.gz
podman-eee0ec97e8eb7436208b7852e7e9ee5974384395.tar.bz2
podman-eee0ec97e8eb7436208b7852e7e9ee5974384395.zip
Add quiet/q flag to podman secret ls
Add quiet/q flag to podman secret ls, which will print only the secret ID. Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/secrets/list.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/cmd/podman/secrets/list.go b/cmd/podman/secrets/list.go
index 8b1956eab..afa9b8887 100644
--- a/cmd/podman/secrets/list.go
+++ b/cmd/podman/secrets/list.go
@@ -34,6 +34,7 @@ type listFlagType struct {
format string
noHeading bool
filter []string
+ quiet bool
}
func init() {
@@ -43,13 +44,20 @@ func init() {
})
flags := lsCmd.Flags()
+
formatFlagName := "format"
flags.StringVar(&listFlag.format, formatFlagName, "{{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.CreatedAt}}\t{{.UpdatedAt}}\t\n", "Format volume output using Go template")
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&entities.SecretInfoReport{}))
+
filterFlagName := "filter"
flags.StringSliceVarP(&listFlag.filter, filterFlagName, "f", []string{}, "Filter secret output")
_ = lsCmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteSecretFilters)
- flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
+
+ noHeadingFlagName := "noheading"
+ flags.BoolVar(&listFlag.noHeading, noHeadingFlagName, false, "Do not print headers")
+
+ quietFlagName := "quiet"
+ flags.BoolVarP(&listFlag.quiet, quietFlagName, "q", false, "Print secret IDs only")
}
func ls(cmd *cobra.Command, args []string) error {
@@ -76,9 +84,21 @@ func ls(cmd *cobra.Command, args []string) error {
Driver: response.Spec.Driver.Name,
})
}
+
+ if listFlag.quiet && !cmd.Flags().Changed("format") {
+ return quietOut(listed)
+ }
+
return outputTemplate(cmd, listed)
}
+func quietOut(responses []*entities.SecretListReport) error {
+ for _, response := range responses {
+ fmt.Println(response.ID)
+ }
+ return nil
+}
+
func outputTemplate(cmd *cobra.Command, responses []*entities.SecretListReport) error {
headers := report.Headers(entities.SecretListReport{}, map[string]string{
"CreatedAt": "CREATED",