Skip to content

Commit

Permalink
added -i option to list to search case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas von Dein committed Dec 23, 2024
1 parent 2f652dc commit a777c9c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions anydb.pod
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ The B<list> subcommand displays a list of all database entries.
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:
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
Expand Down Expand Up @@ -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
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
default mode is "table". The "wide" mode is, as already mentioned, a
more detailed table. Also supported is "json" mode and "template"
Expand Down
23 changes: 12 additions & 11 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions cmd/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,19 @@ func List(conf *cfg.Config) *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",
Long: `List database contents`,
RunE: func(cmd *cobra.Command, args []string) error {
// errors at this stage do not cause the usage to be shown
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
Expand All @@ -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, "/")
Expand Down
7 changes: 7 additions & 0 deletions t/workflow.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit a777c9c

Please sign in to comment.