diff --git a/anydb.1 b/anydb.1 index bc9f696..367a284 100644 --- a/anydb.1 +++ b/anydb.1 @@ -409,6 +409,10 @@ features. .PP If you want to search case insensitive, add the option \f(CW\*(C`\-i\*(C'\fR. .PP +By default anydb only searches through the keys. If you want to search +through the values as well, then use the \f(CW\*(C`\-s\*(C'\fR option, which enables +full-text search. +.PP You can \- as with the \fBget\fR command \- use other output modes. The default mode is \*(L"table\*(R". The \*(L"wide\*(R" mode is, as already mentioned, a more detailed table. Also supported is \*(L"json\*(R" mode and \*(L"template\*(R" @@ -478,7 +482,7 @@ Usage: .PP .Vb 2 \& Usage: -\& anydb export [\-o ] [flags] +\& anydb export \-o [flags] \& \& Aliases: \& export, dump, backup @@ -488,13 +492,13 @@ Usage: \& \-o, \-\-output string output to file .Ve .PP -The database dump is a \s-1JSON\s0 representation of the whole database and -will be printed to \s-1STDOUT\s0 by default. Redirect it to a file or use the -\&\f(CW\*(C`\-o\*(C'\fR option: +The database dump is a \s-1JSON\s0 representation of the whole database and +will be printed to the file specified with the \f(CW\*(C`\-o\*(C'\fR option. If you +specify \*(L"\-\*(R" as the filename, it will be written to \s-1STDIN.\s0 .PP .Vb 2 -\& anydb export > dump.json \& anydb export \-o dump.json +\& anydb export \-o \- > dump.json .Ve .PP Please note, that encrypted values will not be decrypted. This might @@ -508,7 +512,7 @@ Usage: .PP .Vb 2 \& Usage: -\& anydb import [] [flags] +\& anydb import \-i [flags] \& \& Aliases: \& import, restore @@ -519,13 +523,14 @@ Usage: \& \-t, \-\-tags stringArray tags, multiple allowed .Ve .PP -By default the \f(CW\*(C`import\*(C'\fR subcommand reads the \s-1JSON\s0 contents from -\&\s-1STDIN.\s0 You might pipe the dump into it or use the option \f(CW\*(C`\-r\*(C'\fR: +The \f(CW\*(C`import\*(C'\fR subcommand reads the \s-1JSON\s0 contents from +the file specified with the \f(CW\*(C`\-i\*(C'\fR option. If you specify \*(L"\-\*(R" as the +filename, it will be read from \s-1STDIN.\s0 .PP .Vb 3 -\& anydb import < dump.json -\& anydb import \-r dump.json -\& cat dump.json | anydb import +\& anydb import \-i \- < dump.json +\& anydb import \-i dump.json +\& cat dump.json | anydb import \-i \- .Ve .PP If there is already a database, it will be saved by appending a diff --git a/app/db.go b/app/db.go index eafaa73..27b1850 100644 --- a/app/db.go +++ b/app/db.go @@ -53,7 +53,7 @@ type DbInfo struct { Path string } -type DbEntries []DbEntry +type DbEntries []*DbEntry type DbTag struct { Keys []string `json:"key"` @@ -154,7 +154,7 @@ func (db *DB) List(attr *DbAttr, fulltext bool) (DbEntries, error) { } if include { - entries = append(entries, entry) + entries = append(entries, &entry) } return nil @@ -162,6 +162,7 @@ func (db *DB) List(attr *DbAttr, fulltext bool) (DbEntries, error) { return err }) + return entries, err } @@ -392,7 +393,7 @@ func (db *DB) Import(attr *DbAttr) (string, error) { } for _, entry := range entries { - pbentry, err := proto.Marshal(&entry) + pbentry, err := proto.Marshal(entry) if err != nil { return fmt.Errorf("failed to marshall protobuf: %w", err) } @@ -514,7 +515,7 @@ func (db *DB) Getall(attr *DbAttr) (DbEntries, error) { copy(vc, value) entry.Value = vc - entries = append(entries, entry) + entries = append(entries, &entry) return nil }) diff --git a/cmd/anydb.go b/cmd/anydb.go index 07ae3bc..6a11cd0 100644 --- a/cmd/anydb.go +++ b/cmd/anydb.go @@ -234,6 +234,10 @@ SUBCOMMANDS If you want to search case insensitive, add the option "-i". + By default anydb only searches through the keys. If you want to search + through the values as well, then use the "-s" option, which enables + full-text search. + You can - as with the 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" mode. For @@ -293,7 +297,7 @@ SUBCOMMANDS Usage: Usage: - anydb export [-o ] [flags] + anydb export -o [flags] Aliases: export, dump, backup @@ -303,11 +307,11 @@ SUBCOMMANDS -o, --output string output to file The database dump is a JSON representation of the whole database and - will be printed to STDOUT by default. Redirect it to a file or use the - "-o" option: + will be printed to the file specified with the "-o" option. If you + specify "-" as the filename, it will be written to STDIN. - anydb export > dump.json anydb export -o dump.json + anydb export -o - > dump.json Please note, that encrypted values will not be decrypted. This might change in a future version of anydb. @@ -319,7 +323,7 @@ SUBCOMMANDS Usage: Usage: - anydb import [] [flags] + anydb import -i [flags] Aliases: import, restore @@ -329,12 +333,13 @@ SUBCOMMANDS -h, --help help for import -t, --tags stringArray tags, multiple allowed - By default the "import" subcommand reads the JSON contents from STDIN. - You might pipe the dump into it or use the option "-r": + The "import" subcommand reads the JSON contents from the file specified + with the "-i" option. If you specify "-" as the filename, it will be + read from STDIN. - anydb import < dump.json - anydb import -r dump.json - cat dump.json | anydb import + anydb import -i - < dump.json + anydb import -i dump.json + cat dump.json | anydb import -i - If there is already a database, it will be saved by appending a timestamp and a new database with the contents of the dump will be diff --git a/cmd/extra.go b/cmd/extra.go index a2c20f6..d5629ef 100644 --- a/cmd/extra.go +++ b/cmd/extra.go @@ -56,7 +56,9 @@ func Export(conf *cfg.Config) *cobra.Command { } cmd.PersistentFlags().StringVarP(&attr.File, "output-file", "o", "", "filename or - for STDIN") - cmd.MarkPersistentFlagRequired("output-file") + if err := cmd.MarkPersistentFlagRequired("output-file"); err != nil { + panic(err) + } cmd.Aliases = append(cmd.Aliases, "dump") cmd.Aliases = append(cmd.Aliases, "backup") @@ -88,8 +90,10 @@ func Import(conf *cfg.Config) *cobra.Command { } cmd.PersistentFlags().StringVarP(&attr.File, "import-file", "i", "", "filename or - for STDIN") - cmd.MarkPersistentFlagRequired("import-file") cmd.PersistentFlags().StringArrayVarP(&attr.Tags, "tags", "t", nil, "tags, multiple allowed") + if err := cmd.MarkPersistentFlagRequired("import-file"); err != nil { + panic(err) + } cmd.Aliases = append(cmd.Aliases, "restore") diff --git a/output/single.go b/output/single.go index 7bbe74f..d0dd036 100644 --- a/output/single.go +++ b/output/single.go @@ -60,9 +60,9 @@ func Print(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.DbEn fmt.Println(string(jsonentry)) case "wide": - return ListTable(writer, conf, app.DbEntries{*entry}) + return ListTable(writer, conf, app.DbEntries{entry}) case "template": - return ListTemplate(writer, conf, app.DbEntries{*entry}) + return ListTemplate(writer, conf, app.DbEntries{entry}) } return nil