feat(list): adds --count flag for returning a count of matches
This commit is contained in:
parent
e04bcfb306
commit
ad98a1e6c4
4 changed files with 24 additions and 0 deletions
|
|
@ -206,6 +206,12 @@ pda ls --format csv
|
||||||
# dogs,four legged mammals,no expiry
|
# dogs,four legged mammals,no expiry
|
||||||
|
|
||||||
# Or TSV, or Markdown, or HTML.
|
# Or TSV, or Markdown, or HTML.
|
||||||
|
|
||||||
|
# Just the count of entries.
|
||||||
|
pda ls --count
|
||||||
|
# 2
|
||||||
|
pda ls --count --key "d*"
|
||||||
|
# 1
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="center"></p><!-- spacer -->
|
<p align="center"></p><!-- spacer -->
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ func (e *formatEnum) Type() string { return "format" }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
listBase64 bool
|
listBase64 bool
|
||||||
|
listCount bool
|
||||||
listNoKeys bool
|
listNoKeys bool
|
||||||
listNoValues bool
|
listNoValues bool
|
||||||
listNoTTL 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 {
|
if (len(matchers) > 0 || len(valueMatchers) > 0) && len(filtered) == 0 {
|
||||||
switch {
|
switch {
|
||||||
case len(matchers) > 0 && len(valueMatchers) > 0:
|
case len(matchers) > 0 && len(valueMatchers) > 0:
|
||||||
|
|
@ -473,6 +479,7 @@ func renderTable(tw table.Writer) {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Flags().BoolVarP(&listBase64, "base64", "b", false, "view binary data as base64")
|
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(&listNoKeys, "no-keys", false, "suppress the key column")
|
||||||
listCmd.Flags().BoolVar(&listNoValues, "no-values", false, "suppress the value column")
|
listCmd.Flags().BoolVar(&listNoValues, "no-values", false, "suppress the value column")
|
||||||
listCmd.Flags().BoolVar(&listNoTTL, "no-ttl", false, "suppress the TTL column")
|
listCmd.Flags().BoolVar(&listNoTTL, "no-ttl", false, "suppress the TTL column")
|
||||||
|
|
|
||||||
2
testdata/help-list.ct
vendored
2
testdata/help-list.ct
vendored
|
|
@ -10,6 +10,7 @@ Aliases:
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-b, --base64 view binary data as base64
|
-b, --base64 view binary data as base64
|
||||||
|
-c, --count print only the count of matching entries
|
||||||
-o, --format format output format (table|tsv|csv|markdown|html|ndjson) (default table)
|
-o, --format format output format (table|tsv|csv|markdown|html|ndjson) (default table)
|
||||||
-f, --full show full values without truncation
|
-f, --full show full values without truncation
|
||||||
-h, --help help for list
|
-h, --help help for list
|
||||||
|
|
@ -29,6 +30,7 @@ Aliases:
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-b, --base64 view binary data as base64
|
-b, --base64 view binary data as base64
|
||||||
|
-c, --count print only the count of matching entries
|
||||||
-o, --format format output format (table|tsv|csv|markdown|html|ndjson) (default table)
|
-o, --format format output format (table|tsv|csv|markdown|html|ndjson) (default table)
|
||||||
-f, --full show full values without truncation
|
-f, --full show full values without truncation
|
||||||
-h, --help help for list
|
-h, --help help for list
|
||||||
|
|
|
||||||
9
testdata/list-count.ct
vendored
Normal file
9
testdata/list-count.ct
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
$ pda set a@lc val-a
|
||||||
|
$ pda set b@lc val-b
|
||||||
|
$ pda set c@lc val-c
|
||||||
|
$ pda ls lc --count
|
||||||
|
3
|
||||||
|
$ pda ls lc --count --key "a*"
|
||||||
|
1
|
||||||
|
$ pda ls lc --count --key "z*"
|
||||||
|
0
|
||||||
Loading…
Add table
Add a link
Reference in a new issue