From a777c9cab4dd9040edb2710daa42cc9d3df54638 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 23 Dec 2024 19:49:42 +0100 Subject: [PATCH] added -i option to list to search case insensitive --- TODO.md | 1 - anydb.pod | 8 ++++++-- cfg/config.go | 23 ++++++++++++----------- cmd/crud.go | 9 +++++++-- t/workflow.txtar | 7 +++++++ 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/TODO.md b/TODO.md index 8b6e987..b205066 100644 --- a/TODO.md +++ b/TODO.md @@ -2,4 +2,3 @@ - mime-type => exec app + value - add waitgroup to db.go funcs - RestList does not support any params? -- case sensitive search: make it insensitive or add -i diff --git a/anydb.pod b/anydb.pod index f61080b..0e626c5 100644 --- a/anydb.pod +++ b/anydb.pod @@ -206,14 +206,16 @@ The B subcommand displays a list of all database entries. Usage: Usage: - anydb list [] [-t ] [-m ] [-n -N] [-T ] [flags] + anydb list [] [-t ] [-m ] [-n -N] [-T ] [-i] [flags] Aliases: list, /, ls Flags: + -i, --case-insensitive filter case insensitive -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-human do not translate to human readable values -t, --tags stringArray tags, multiple allowed @@ -250,6 +252,8 @@ L. Please note, that this regexp dialect is not PCRE compatible, but supports most of its features. +If you want to search case insensitive, add the option C<-i>. + You can - as with the B command - use other output modes. The default mode is "table". The "wide" mode is, as already mentioned, a more detailed table. Also supported is "json" mode and "template" diff --git a/cfg/config.go b/cfg/config.go index 756bee1..47ff633 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -26,23 +26,24 @@ import ( "github.com/tlinden/anydb/common" ) -var Version string = "v0.0.6" +var Version string = "v0.0.7" type BucketConfig struct { Encrypt bool } type Config struct { - Debug bool - Dbfile string - Dbbucket string - Template string - Mode string // wide, table, yaml, json - NoHeaders bool - NoHumanize bool - Encrypt bool // one entry - Listen string - Buckets map[string]BucketConfig // config file only + Debug bool + Dbfile string + Dbbucket string + Template string + Mode string // wide, table, yaml, json + NoHeaders bool + NoHumanize bool + Encrypt bool // one entry + CaseInsensitive bool + Listen string + Buckets map[string]BucketConfig // config file only Tags []string // internal DB *app.DB // internal diff --git a/cmd/crud.go b/cmd/crud.go index b797336..fb72b2e 100644 --- a/cmd/crud.go +++ b/cmd/crud.go @@ -188,7 +188,7 @@ func List(conf *cfg.Config) *cobra.Command { ) var cmd = &cobra.Command{ - Use: "list [] [-t ] [-m ] [-n -N] [-T ]", + Use: "list [] [-t ] [-m ] [-n -N] [-T ] [-i]", Short: "List database contents", Long: `List database contents`, RunE: func(cmd *cobra.Command, args []string) error { @@ -196,7 +196,11 @@ func List(conf *cfg.Config) *cobra.Command { cmd.SilenceUsage = true if len(args) > 0 { - attr.Args = args + if conf.CaseInsensitive { + attr.Args = []string{"(?i)" + args[0]} + } else { + attr.Args = args + } } // turn comma list into slice, if needed @@ -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(&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.CaseInsensitive, "case-insensitive", "i", false, "filter case insensitive") cmd.PersistentFlags().StringArrayVarP(&attr.Tags, "tags", "t", nil, "tags, multiple allowed") cmd.Aliases = append(cmd.Aliases, "/") diff --git a/t/workflow.txtar b/t/workflow.txtar index a1e30b8..cf10205 100644 --- a/t/workflow.txtar +++ b/t/workflow.txtar @@ -18,6 +18,9 @@ # simple entry exec anydb -f test.db set foo bar +# single entry uc() +exec anydb -f test.db set MUCHAS gracias + # entry with tags 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 stdout bar +# list with -i filter +exec anydb -f test.db list -i mucha +stdout MUCHA + # get single entry exec anydb -f test.db get color stdout grey