-
Notifications
You must be signed in to change notification settings - Fork 0
/
anydb.1
759 lines (759 loc) · 24.5 KB
/
anydb.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "ANYDB 1"
.TH ANYDB 1 "2024-12-30" "1" "User Commands"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "anydb"
.IX Header "anydb"
anydb \- a personal key value store
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\& Usage:
\& anydb <command> [options] [flags]
\& anydb [command]
\&
\& Available Commands:
\& completion Generate the autocompletion script for the specified shell
\& del Delete key
\& edit Edit a key
\& export Export database to json
\& get Retrieve value for a key
\& help Help about any command
\& import Import database dump
\& info info
\& list List database contents
\& man show manual page
\& serve run REST API listener
\& set Insert key/value pair
\&
\& Flags:
\& \-b, \-\-bucket string use other bucket (default: data) (default "data")
\& \-c, \-\-config string toml config file
\& \-f, \-\-dbfile string DB file to use (default "/home/scip/.config/anydb/default.db")
\& \-d, \-\-debug Enable debugging
\& \-h, \-\-help help for anydb
\& \-v, \-\-version Print program version
\&
\& Use "anydb [command] \-\-help" for more information about a command.
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Anydb is a commandline personal key value store, it is simple to use
and can be used to store anything you'd like, even binary files
etc. It uses a key/value store (bbolt) in your home directory.
.PP
The tool provides a number of subcommands to use it, there are global
options and each subcommand has its own set of options.
.SH "GLOBAL OPTIONS"
.IX Header "GLOBAL OPTIONS"
.ie n .IP """\-f, \-\-dbfile filename""" 4
.el .IP "\f(CW\-f, \-\-dbfile filename\fR" 4
.IX Item "-f, --dbfile filename"
The default location of your databas is
\&\f(CW\*(C`$HOME/.config/anydb/default.db\*(C'\fR. You can change this with the \f(CW\*(C`\-f\*(C'\fR
option.
.ie n .IP """\-b, \-\-bucket name""" 4
.el .IP "\f(CW\-b, \-\-bucket name\fR" 4
.IX Item "-b, --bucket name"
Data in a bbolt key-value-store are managed in so called
buckets. These are kind of namespaces, where each key must be
unique. However, a database may contain more than one bucket.
.Sp
By default anydb uses a bucket named \*(L"data\*(R", but you can change this
using the option \f(CW\*(C`\-b\*(C'\fR.
.Sp
Buckets can be configured to always encrypt values, see \s-1ENCRYTPTION\s0.
.ie n .IP """\-c, \-\-config filename""" 4
.el .IP "\f(CW\-c, \-\-config filename\fR" 4
.IX Item "-c, --config filename"
Under normal circumstances you don't need a configuration file. But if
you want, you can provide one using the option \f(CW\*(C`\-c\*(C'\fR.
.Sp
Anydb looks for a couple of default locations for a config file. You
only need this option if you want to supply a configuration on a
non-standard location. See \s-1CONFIGURATION\s0 for more details.
.ie n .IP """\-d, \-\-debug""" 4
.el .IP "\f(CW\-d, \-\-debug\fR" 4
.IX Item "-d, --debug"
Enable debug output.
.ie n .IP """\-h, \-\-help""" 4
.el .IP "\f(CW\-h, \-\-help\fR" 4
.IX Item "-h, --help"
Show the usage of anydb.
.ie n .IP """\-v, \-\-version""" 4
.el .IP "\f(CW\-v, \-\-version\fR" 4
.IX Item "-v, --version"
Show the program version.
.PP
All of these options can be used with subcommands as well.
.SH "SUBCOMMANDS"
.IX Header "SUBCOMMANDS"
.SS "completion"
.IX Subsection "completion"
The \fBcompletion\fR command can be used to setup completion for
anydb. Just put something like this into your shell's configuration
file:
.PP
.Vb 1
\& source <(anydb completion bash)
.Ve
.PP
If you use another shell, specify it instead of bash, of course.
.SS "set"
.IX Subsection "set"
The \fBset\fR command is being used to insert or update a key-value pair.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb set <key> [<value> | \-r <file>] [\-t <tag>] [flags]
\&
\& Aliases:
\& set, add, s, +
\&
\& Flags:
\& \-e, \-\-encrypt encrypt value
\& \-r, \-\-file string Filename or \- for STDIN
\& \-h, \-\-help help for set
\& \-t, \-\-tags tag,tag,... tags, multiple allowed
.Ve
.PP
The standard way to insert a new entry is really simple:
.PP
.Vb 1
\& anydb set key value
.Ve
.PP
If you don't specify a value, anydb expects you to feed it some data
via \s-1STDIN.\s0 For example:
.PP
.Vb 1
\& anydb set key < file
.Ve
.PP
You might as well specify a file directly using the \f(CW\*(C`\-f\*(C'\fR option:
.PP
.Vb 1
\& anydb set key \-f file
.Ve
.PP
Values can be encrypted using \fBChaCha20Poly1305\fR when you specify the
\&\f(CW\*(C`\-e\*(C'\fR option. Anydb will ask you interactively for a passphrase. You
can also provide the passphrase using the environment variable
\&\f(CW\*(C`ANYDB_PASSWORD\*(C'\fR. To encrypt the value, a cryptographically secure
key will be derived from the passphrase using the ArgonID2
algorithm. Each value can be encrypted with another passphrase. So,
the database itself is not encrypted, just the values.
.PP
You can supply tags by using the option \f(CW\*(C`\-t\*(C'\fR. Multiple tags can be
provided either by separating them with a comma or by using multiple
\&\f(CW\*(C`\-t\*(C'\fR parameters:
.PP
.Vb 2
\& anydb set key value \-t tag1,tag2
\& anydb set key value \-t tag1 \-t tag2
.Ve
.PP
You can later filter entries by tag or by a combination of tags.
.PP
To edit or modify an entry, just use the \fBset\fR command with the same
key, the value in the database will be overwritten with the new
value. An alternative option is the \fBedit\fR command, see below.
.SS "get"
.IX Subsection "get"
To retrieve the value of a key, use the \fBget\fR subcommand.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb get <key> [\-o <file>] [\-m <mode>] [\-n \-N] [\-T <tpl>] [flags]
\&
\& Aliases:
\& get, show, g, .
\&
\& Flags:
\& \-h, \-\-help help for get
\& \-m, \-\-mode string output format (simple|wide|json|template) (default \*(Aqsimple\*(Aq)
\& \-n, \-\-no\-headers omit headers in tables
\& \-N, \-\-no\-human do not translate to human readable values
\& \-o, \-\-output string output value to file (ignores \-m)
\& \-T, \-\-template string go template for \*(Aq\-m template\*(Aq
.Ve
.PP
In its simplest form you just call the \fBget\fR subcommand with the key
you want to have the value for. The value is being printed to \s-1STDOUT\s0
by default:
.PP
.Vb 1
\& anydb get key
.Ve
.PP
If the value is binary content, it will not just being printed. In
those cases you need to either redirect output into a file or use the
option \f(CW\*(C`\-o\*(C'\fR to write to a file:
.PP
.Vb 2
\& anydb get key > file
\& anydb get key \-o file
.Ve
.PP
If the value is encrypted, you will be asked for the passphrase to
decrypt it. If the environment variable \f(CW\*(C`ANYDB_PASSWORD\*(C'\fR is set, its
value will be used instead.
.PP
There are different output modes you can choose from: simple, wide and
json. The \*(L"simple\*(R" mode is the default one, it just prints the value
as is. The \*(L"wide\*(R" mode prints a tabular output similar to the \fBlist\fR
subcommand, see there for more details. The options \f(CW\*(C`\-n\*(C'\fR and \f(CW\*(C`\-N\*(C'\fR
have the same meaning as in the list command. The \*(L"json\*(R" mode prints
the raw \s-1JSON\s0 representation of the whole database entry. Decryption
will only take place in \*(L"simple\*(R" and \*(L"json\*(R" mode. The \*(L"template\*(R" mode
provides the most flexibily, it is detailed in the section
\&\s-1TEMPLATES\s0.
.SS "list"
.IX Subsection "list"
The \fBlist\fR subcommand displays a list of all database entries.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb list [<filter\-regex> | \-t <tag> ] [\-m <mode>] [\-nNif] [\-T <tpl>] [flags]
\&
\& Aliases:
\& list, ls, /, find, search
\&
\& 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 \*(Aqtable\*(Aq)
\& \-n, \-\-no\-headers omit headers in tables
\& \-N, \-\-no\-human do not translate to human readable values
\& \-s, \-\-search\-fulltext perform a full text search
\& \-t, \-\-tags stringArray tags, multiple allowed
\& \-T, \-\-template string go template for \*(Aq\-m template\*(Aq
\& \-l, \-\-wide\-output output mode: wide
.Ve
.PP
In its simplest form \- without any options \- , the \fBlist\fR command
just prints all keys with their values to \s-1STDOUT.\s0 Values are being
truncated to maximum of 60 characters, that is, multiline values are
not completely shown in order to keep the tabular view readable.
.PP
To get more informations about each entry, use the \f(CW\*(C`\-o wide\*(C'\fR or \f(CW\*(C`\-l\*(C'\fR
option. In addition to the key and value also the size, update
timestamp and tags will be printed. Time and size values are converted
into a human readable form, you can suppress this behavior with the
\&\f(CW\*(C`\-N\*(C'\fR option. You may omit the headers using the option \f(CW\*(C`\-n\*(C'\fR
.PP
Sometimes you might want to filter the list of entries. Either because
your database grew too large or because you're searching for
something. In that case you have two options: You may supply one or
more tags or provide a filter regexp. To filter by tag, do:
.PP
.Vb 3
\& anydb list \-t tag1
\& anydb list \-t tag1,tag2
\& anydb list \-t tag1 \-t tag2
.Ve
.PP
To filter using a regular expression, do:
.PP
.Vb 1
\& anydb list "foo.*bar"
.Ve
.PP
Regular expressions follow the golang \fBre2\fR syntax. For more details
about the syntax, refer to
<https://github.com/google/re2/wiki/Syntax>. Please note, that this
regexp dialect is not \s-1PCRE\s0 compatible, but supports most of its
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"
mode. For details about using templates see \s-1TEMPLATES\s0.
.SS "del"
.IX Subsection "del"
Use the \fBdel\fR command to delete database entries.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb del <key> [flags]
\&
\& Aliases:
\& del, d, rm
\&
\& Flags:
\& \-h, \-\-help help for del
.Ve
.PP
The subcommand \fBdel\fR does not provide any further options, it just
deletes the entry referred to by the given key. No questions are being
asked.
.SS "edit"
.IX Subsection "edit"
The \fBedit\fR command makes it easier to modify larger entries.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb edit <key> [flags]
\&
\& Aliases:
\& edit, modify, mod, ed, vi
\&
\& Flags:
\& \-h, \-\-help help for edit
.Ve
.PP
The subcommand \fBedit\fR does not provide any further options. It
works like this:
.IP "1. Write the value info a temporary file." 4
.IX Item "1. Write the value info a temporary file."
.PD 0
.IP "2. Execute the editor (which one, see below!) with that file." 4
.IX Item "2. Execute the editor (which one, see below!) with that file."
.IP "3. Now you can edit the file and save+close it when done." 4
.IX Item "3. Now you can edit the file and save+close it when done."
.IP "4. Anydb picks up the file and if the content has changed, puts its value into the \s-1DB.\s0" 4
.IX Item "4. Anydb picks up the file and if the content has changed, puts its value into the DB."
.PD
.PP
By default anydb executes the \f(CW\*(C`vi\*(C'\fR command. You can modify this
behavior by setting the environment variable \f(CW\*(C`EDITOR\*(C'\fR appropriately.
.PP
Please note, that this does not work with binary content!
.SS "export"
.IX Subsection "export"
Since the bbolt database file is not portable across platforms (it is
bound to the endianess of the \s-1CPU\s0 it was being created on), you might
want to create a backup file of your database. You can do this with
the \fBexport\fR subcommand.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb export \-o <json filename> [flags]
\&
\& Aliases:
\& export, dump, backup
\&
\& Flags:
\& \-h, \-\-help help for export
\& \-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 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 \-o dump.json
\& anydb export \-o \- > dump.json
.Ve
.PP
Please note, that encrypted values will not be decrypted. This might
change in a future version of anydb.
.SS "import"
.IX Subsection "import"
The \fBimport\fR subcommand can be used to restore a database from a \s-1JSON\s0
dump.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb import \-i <json file> [flags]
\&
\& Aliases:
\& import, restore
\&
\& Flags:
\& \-r, \-\-file string Filename or \- for STDIN
\& \-h, \-\-help help for import
\& \-t, \-\-tags stringArray tags, multiple allowed
.Ve
.PP
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 \-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
timestamp and a new database with the contents of the dump will be
created.
.SS "serve"
.IX Subsection "serve"
Anydb provides a RESTful \s-1API,\s0 which you can use to manage the database
from somewhere else. The \s-1API\s0 does not provide any authentication or
any other security measures, so better only use it on localhost.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb serve [\-l host:port] [flags]
\&
\& Flags:
\& \-h, \-\-help help for serve
\& \-l, \-\-listen string host:port (default "localhost:8787")
.Ve
.PP
To start the listener, just execute the \fBserve\fR subcommand. You can
tweak the ip address and tcp port using the \f(CW\*(C`\-l\*(C'\fR option. The listener
will not fork and run in the foreground. Logs are being printed to
\&\s-1STDOUT\s0 as long as the listener runs.
.PP
For more details about the \s-1API,\s0 please see the \*(L"\s-1REST API\*(R"\s0 section.
.SS "info"
.IX Subsection "info"
The \fBinfo\fR subcommand shows you some information about your current
database.
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb info [flags]
\&
\& Flags:
\& \-h, \-\-help help for info
\& \-N, \-\-no\-human do not translate to human readable values
.Ve
.PP
Data being shown are: filename and size, number of keys per bucket. If
you supply the \f(CW\*(C`\-d\*(C'\fR option (debug), some bbolt internals are being
displayed as well.
.SS "man"
.IX Subsection "man"
The \fBman\fR subcommand shows an unformatted text variant of the manual
page (which are currently reading).
.PP
Usage:
.PP
.Vb 2
\& Usage:
\& anydb man [flags]
\&
\& Flags:
\& \-h, \-\-help help for man
.Ve
.PP
The manual is being piped into the \f(CW\*(C`more\*(C'\fR command, which is being
expected to exist according to the \s-1POSIX\s0 standard on all supported
unix platforms. It might not work on Windows.
.SH "TEMPLATES"
.IX Header "TEMPLATES"
The \fBget\fR and \fBlist\fR commands support a template feature, which is
very handy to create you own kind of formatting. The template syntax
being used is the \s-1GO\s0 template language, refer to
<https://pkg.go.dev/text/template> for details.
.PP
Each template operates on one or more entries, no loop construct is
required, the template provided applies to every matching entry
separatley.
.PP
The following template variables can be used:
.IP "\fBKey\fR \- string" 4
.IX Item "Key - string"
.PD 0
.IP "\fBValue\fR \- string" 4
.IX Item "Value - string"
.IP "\fBBin\fR \- []byte" 4
.IX Item "Bin - []byte"
.IP "\fBCreated\fR \- time.Time" 4
.IX Item "Created - time.Time"
.IP "\fBTags\fR \- []string" 4
.IX Item "Tags - []string"
.IP "\fBEncrypted\fR bool" 4
.IX Item "Encrypted bool"
.PD
.PP
Prepend a single dot (\*(L".\*(R") before each variable name.
.PP
Here are some examples how to use the feature:
.PP
Only show the keys of all entries:
.PP
.Vb 1
\& anydb list \-m template \-T "{{ .Key }}"
.Ve
.PP
Format the list in a way so that is possible to evaluate it in a
shell:
.PP
.Vb 2
\& eval $(anydb get foo \-m template \-T "key=\*(Aq{{ .Key }}\*(Aq value=\*(Aq{{ .Value }}\*(Aq ts=\*(Aq{{ .Created}}\*(Aq")
\& echo "Key: $key, Value: $value"
.Ve
.PP
Print the values in \s-1CSV\s0 format \s-1ONLY\s0 if they have some tag:
.PP
.Vb 1
\& anydb list \-m template \-T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created}}{{ end }}"
.Ve
.SH "CONFIGURATION"
.IX Header "CONFIGURATION"
Anydb looks at the following locations for a configuration file, in
that order:
.ie n .IP """$HOME/.config/anydb/anydb.toml""" 4
.el .IP "\f(CW$HOME/.config/anydb/anydb.toml\fR" 4
.IX Item "$HOME/.config/anydb/anydb.toml"
.PD 0
.ie n .IP """$HOME/.anydb.toml""" 4
.el .IP "\f(CW$HOME/.anydb.toml\fR" 4
.IX Item "$HOME/.anydb.toml"
.ie n .IP """anydb.toml"" in the current directory" 4
.el .IP "\f(CWanydb.toml\fR in the current directory" 4
.IX Item "anydb.toml in the current directory"
.ie n .IP "or specify one using ""\-c""" 4
.el .IP "or specify one using \f(CW\-c\fR" 4
.IX Item "or specify one using -c"
.PD
.PP
The configuration format uses the \s-1TOML\s0 language, refer to
<https://toml.io/en/> for more details. The key names correspond to
the commandline options in most cases.
.PP
Configuration follows a certain precedence: the files are tried to be
read in the given order, followed by commandline options. That is, the
last configuration file wins, unless the user provides a commandline
option, then this setting will be taken.
.PP
A complete configuration file might look like this:
.PP
.Vb 7
\& # defaults
\& dbfile = "~/.config/anydb/default.db"
\& dbbucket = "data"
\& noheaders = false
\& nohumanize = false
\& encrypt = false
\& listen = "localhost:8787"
\&
\& # different setups for different buckets
\& [buckets.data]
\& encrypt = true
\&
\& [buckets.test]
\& encrypt = false
.Ve
.PP
Under normal circumstances you don't need a configuration
file. However, if you want to use different buckets, then this might
be a handy option. Buckets are being configured in ini-style with the
term \*(L"bucket.\*(R" followed by the bucket name. In the example above we
enable encryption for the default bucket \*(L"data\*(R" and disable it for a
bucket \*(L"test\*(R". To use different buckets, use the \f(CW\*(C`\-b\*(C'\fR option.
.SH "REST API"
.IX Header "REST API"
The subcommand \fBserve\fR starts a simple \s-1HTTP\s0 service, which responds
to RESTful \s-1HTTP\s0 requests. The listener responds to all requests with a
\&\s-1JSON\s0 encoded response. The response contains the status and the
content \- if any \- of the requested resource.
.PP
The following requests are supported:
.IP "\fB\s-1GET\s0 /anydb/v1/\fR" 4
.IX Item "GET /anydb/v1/"
Returns a \s-1JSON\s0 encoded list of all entries.
.IP "\fB\s-1GET\s0 /anydb/v1/key\fR" 4
.IX Item "GET /anydb/v1/key"
Returns the \s-1JSON\s0 encoded entry, if found.
.IP "\fB\s-1PUT\s0 /anydb/v1/\fR" 4
.IX Item "PUT /anydb/v1/"
Create an entry. Expects a \s-1JSON\s0 encoded request object in \s-1POST\s0 data.
.IP "\fB\s-1DELETE\s0 /anydb/v1/key\fR" 4
.IX Item "DELETE /anydb/v1/key"
Delete an entry.
.PP
Some curl example calls to the \s-1API:\s0
.PP
Post a new key:
curl \-X \s-1PUT\s0 localhost:8787/anydb/v1/ \e
\-H 'Content\-Type: application/json' \e
\-d '{\*(L"key\*(R":\*(L"foo\*(R",\*(L"val\*(R":\*(L"bar\*(R"}'
.PP
Retrieve the value:
.PP
.Vb 1
\& curl localhost:8787/anydb/v1/foo
.Ve
.PP
List all keys:
.PP
.Vb 1
\& curl localhost:8787/anydb/v1/
.Ve
.SH "BUGS"
.IX Header "BUGS"
In order to report a bug, unexpected behavior, feature requests
or to submit a patch, please open an issue on github:
<https://github.com/TLINDEN/anydb/issues>.
.PP
Please repeat the failing command with debugging enabled \f(CW\*(C`\-d\*(C'\fR and
include the output in the issue.
.SH "LIMITATIONS"
.IX Header "LIMITATIONS"
The \s-1REST API\s0 list request doesn't provide any filtering capabilities yet.
.SH "LICENSE"
.IX Header "LICENSE"
This software is licensed under the \s-1GNU GENERAL PUBLIC LICENSE\s0 version 3.
.PP
Copyright (c) 2024 by Thomas von Dein
.SH "AUTHORS"
.IX Header "AUTHORS"
Thomas von Dein \fBtom \s-1AT\s0 vondein \s-1DOT\s0 org\fR