feat(list): adds --count flag for returning a count of matches

This commit is contained in:
Lewis Wynne 2026-02-11 17:24:55 +00:00
parent e04bcfb306
commit ad98a1e6c4
4 changed files with 24 additions and 0 deletions

View file

@ -58,6 +58,7 @@ func (e *formatEnum) Type() string { return "format" }
var (
listBase64 bool
listCount bool
listNoKeys bool
listNoValues bool
listNoTTL bool
@ -161,6 +162,11 @@ func list(cmd *cobra.Command, args []string) error {
}
}
if listCount {
fmt.Fprintln(cmd.OutOrStdout(), len(filtered))
return nil
}
if (len(matchers) > 0 || len(valueMatchers) > 0) && len(filtered) == 0 {
switch {
case len(matchers) > 0 && len(valueMatchers) > 0:
@ -473,6 +479,7 @@ func renderTable(tw table.Writer) {
func init() {
listCmd.Flags().BoolVarP(&listBase64, "base64", "b", false, "view binary data as base64")
listCmd.Flags().BoolVarP(&listCount, "count", "c", false, "print only the count of matching entries")
listCmd.Flags().BoolVar(&listNoKeys, "no-keys", false, "suppress the key column")
listCmd.Flags().BoolVar(&listNoValues, "no-values", false, "suppress the value column")
listCmd.Flags().BoolVar(&listNoTTL, "no-ttl", false, "suppress the TTL column")