mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-16 20:10:59 +01:00
added -i option to list to search case insensitive
This commit is contained in:
1
TODO.md
1
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
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -188,7 +188,7 @@ 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 {
|
||||
@@ -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, "/")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user