added -i option to list to search case insensitive

This commit is contained in:
2024-12-23 19:49:42 +01:00
parent 2f652dc57d
commit a777c9cab4
5 changed files with 32 additions and 16 deletions

View File

@@ -2,4 +2,3 @@
- mime-type => exec app + value - mime-type => exec app + value
- add waitgroup to db.go funcs - add waitgroup to db.go funcs
- RestList does not support any params? - RestList does not support any params?
- case sensitive search: make it insensitive or add -i

View File

@@ -206,14 +206,16 @@ The B<list> subcommand displays a list of all database entries.
Usage: Usage:
Usage: Usage:
anydb list [<filter-regex>] [-t <tag>] [-m <mode>] [-n -N] [-T <tpl>] [flags] anydb list [<filter-regex>] [-t <tag>] [-m <mode>] [-n -N] [-T <tpl>] [-i] [flags]
Aliases: Aliases:
list, /, ls list, /, ls
Flags: Flags:
-i, --case-insensitive filter case insensitive
-h, --help help for list -h, --help help for list
-m, --mode string output format (table|wide|json|template), wide is a verbose table. (default 'table') -m, --mode string output format (table|wide|json|template),
wide is a verbose table. (default 'table')
-n, --no-headers omit headers in tables -n, --no-headers omit headers in tables
-N, --no-human do not translate to human readable values -N, --no-human do not translate to human readable values
-t, --tags stringArray tags, multiple allowed -t, --tags stringArray tags, multiple allowed
@@ -250,6 +252,8 @@ L<https://github.com/google/re2/wiki/Syntax>. Please note, that this
regexp dialect is not PCRE compatible, but supports most of its regexp dialect is not PCRE compatible, but supports most of its
features. features.
If you want to search case insensitive, add the option C<-i>.
You can - as with the B<get> command - use other output modes. The You can - as with the B<get> command - use other output modes. The
default mode is "table". The "wide" mode is, as already mentioned, a default mode is "table". The "wide" mode is, as already mentioned, a
more detailed table. Also supported is "json" mode and "template" more detailed table. Also supported is "json" mode and "template"

View File

@@ -26,7 +26,7 @@ import (
"github.com/tlinden/anydb/common" "github.com/tlinden/anydb/common"
) )
var Version string = "v0.0.6" var Version string = "v0.0.7"
type BucketConfig struct { type BucketConfig struct {
Encrypt bool Encrypt bool
@@ -41,6 +41,7 @@ type Config struct {
NoHeaders bool NoHeaders bool
NoHumanize bool NoHumanize bool
Encrypt bool // one entry Encrypt bool // one entry
CaseInsensitive bool
Listen string Listen string
Buckets map[string]BucketConfig // config file only Buckets map[string]BucketConfig // config file only

View File

@@ -188,7 +188,7 @@ func List(conf *cfg.Config) *cobra.Command {
) )
var cmd = &cobra.Command{ var cmd = &cobra.Command{
Use: "list [<filter-regex>] [-t <tag>] [-m <mode>] [-n -N] [-T <tpl>]", Use: "list [<filter-regex>] [-t <tag>] [-m <mode>] [-n -N] [-T <tpl>] [-i]",
Short: "List database contents", Short: "List database contents",
Long: `List database contents`, Long: `List database contents`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
@@ -196,8 +196,12 @@ func List(conf *cfg.Config) *cobra.Command {
cmd.SilenceUsage = true cmd.SilenceUsage = true
if len(args) > 0 { if len(args) > 0 {
if conf.CaseInsensitive {
attr.Args = []string{"(?i)" + args[0]}
} else {
attr.Args = args attr.Args = args
} }
}
// turn comma list into slice, if needed // turn comma list into slice, if needed
if len(attr.Tags) == 1 && strings.Contains(attr.Tags[0], ",") { if len(attr.Tags) == 1 && strings.Contains(attr.Tags[0], ",") {
@@ -222,6 +226,7 @@ func List(conf *cfg.Config) *cobra.Command {
cmd.PersistentFlags().BoolVarP(&wide, "wide-output", "l", false, "output mode: wide") cmd.PersistentFlags().BoolVarP(&wide, "wide-output", "l", false, "output mode: wide")
cmd.PersistentFlags().BoolVarP(&conf.NoHeaders, "no-headers", "n", false, "omit headers in tables") cmd.PersistentFlags().BoolVarP(&conf.NoHeaders, "no-headers", "n", false, "omit headers in tables")
cmd.PersistentFlags().BoolVarP(&conf.NoHumanize, "no-human", "N", false, "do not translate to human readable values") cmd.PersistentFlags().BoolVarP(&conf.NoHumanize, "no-human", "N", false, "do not translate to human readable values")
cmd.PersistentFlags().BoolVarP(&conf.CaseInsensitive, "case-insensitive", "i", false, "filter case insensitive")
cmd.PersistentFlags().StringArrayVarP(&attr.Tags, "tags", "t", nil, "tags, multiple allowed") cmd.PersistentFlags().StringArrayVarP(&attr.Tags, "tags", "t", nil, "tags, multiple allowed")
cmd.Aliases = append(cmd.Aliases, "/") cmd.Aliases = append(cmd.Aliases, "/")

View File

@@ -18,6 +18,9 @@
# simple entry # simple entry
exec anydb -f test.db set foo bar exec anydb -f test.db set foo bar
# single entry uc()
exec anydb -f test.db set MUCHAS gracias
# entry with tags # entry with tags
exec anydb -f test.db set color grey -t flower,plant exec anydb -f test.db set color grey -t flower,plant
@@ -37,6 +40,10 @@ exec anydb -f test.db list -t flower
exec anydb -f test.db list b.r exec anydb -f test.db list b.r
stdout bar stdout bar
# list with -i filter
exec anydb -f test.db list -i mucha
stdout MUCHA
# get single entry # get single entry
exec anydb -f test.db get color exec anydb -f test.db get color
stdout grey stdout grey