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>
This commit is contained in:
parent
351028b1ac
commit
eee0ec97e8
|
@ -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",
|
||||
|
|
|
@ -30,7 +30,11 @@ Format secret output using Go template.
|
|||
|
||||
#### **--noheading**
|
||||
|
||||
Omit the table headings from the listing of secrets. .
|
||||
Omit the table headings from the listing of secrets.
|
||||
|
||||
#### **--quiet**, **-q**
|
||||
|
||||
Print secret IDs only.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
|
|
|
@ -145,6 +145,36 @@ var _ = Describe("Podman secret", func() {
|
|||
|
||||
})
|
||||
|
||||
It("podman secret ls --quiet", func() {
|
||||
secretFilePath := filepath.Join(podmanTest.TempDir, "secret")
|
||||
err := ioutil.WriteFile(secretFilePath, []byte("mysecret"), 0755)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
secretName := "a"
|
||||
|
||||
session := podmanTest.Podman([]string{"secret", "create", secretName, secretFilePath})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
secretID := session.OutputToString()
|
||||
|
||||
list := podmanTest.Podman([]string{"secret", "ls", "-q"})
|
||||
list.WaitWithDefaultTimeout()
|
||||
Expect(list).Should(Exit(0))
|
||||
Expect(list.OutputToString()).To(Equal(secretID))
|
||||
|
||||
list = podmanTest.Podman([]string{"secret", "ls", "--quiet"})
|
||||
list.WaitWithDefaultTimeout()
|
||||
Expect(list).Should(Exit(0))
|
||||
Expect(list.OutputToString()).To(Equal(secretID))
|
||||
|
||||
// Prefer format over quiet
|
||||
list = podmanTest.Podman([]string{"secret", "ls", "-q", "--format", "{{.Name}}"})
|
||||
list.WaitWithDefaultTimeout()
|
||||
Expect(list).Should(Exit(0))
|
||||
Expect(list.OutputToString()).To(Equal(secretName))
|
||||
|
||||
})
|
||||
|
||||
It("podman secret ls with filters", func() {
|
||||
secretFilePath := filepath.Join(podmanTest.TempDir, "secret")
|
||||
err := ioutil.WriteFile(secretFilePath, []byte("mysecret"), 0755)
|
||||
|
|
Loading…
Reference in New Issue