feat(globs): glob support for dump/restore, extracts some shared logic

This commit is contained in:
Lewis Wynne 2025-12-17 22:18:15 +00:00
parent 9869b663e2
commit 7890e9451d
9 changed files with 141 additions and 57 deletions

8
testdata/dump__glob__ok.ct vendored Normal file
View file

@ -0,0 +1,8 @@
$ pda set a1 1
$ pda set a2 2
$ pda set b1 3
$ pda dump --glob a*
{"key":"a1","value":"1","encoding":"text"}
{"key":"a2","value":"2","encoding":"text"}
$ pda dump --glob c* --> FAIL
Error: cannot dump '@default': No matches for pattern

View file

@ -10,6 +10,8 @@ Aliases:
Flags:
-e, --encoding string value encoding: auto, base64, or text (default "auto")
-g, --glob strings Filter keys with glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for dump
--secret Include entries marked as secret
Dump all key/value pairs as NDJSON
@ -22,5 +24,7 @@ Aliases:
Flags:
-e, --encoding string value encoding: auto, base64, or text (default "auto")
-g, --glob strings Filter keys with glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for dump
--secret Include entries marked as secret

View file

@ -9,8 +9,10 @@ Aliases:
restore, import
Flags:
-f, --file string Path to an NDJSON dump (defaults to stdin)
-h, --help help for restore
-f, --file string Path to an NDJSON dump (defaults to stdin)
-g, --glob strings Restore keys matching glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for restore
Restore key/value pairs from an NDJSON dump
Usage:
@ -20,5 +22,7 @@ Aliases:
restore, import
Flags:
-f, --file string Path to an NDJSON dump (defaults to stdin)
-h, --help help for restore
-f, --file string Path to an NDJSON dump (defaults to stdin)
-g, --glob strings Restore keys matching glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for restore

15
testdata/restore__glob__ok.ct vendored Normal file
View file

@ -0,0 +1,15 @@
$ pda set a1 1
$ pda set a2 2
$ pda set b1 3
$ fecho dumpfile {"key":"a1","value":"1","encoding":"text"} {"key":"a2","value":"2","encoding":"text"} {"key":"b1","value":"3","encoding":"text"}
$ pda del a1 a2 b1 --force
$ pda restore --glob a* --file dumpfile
Restored 2 entries into @default
$ pda get a1
1
$ pda get a2
2
$ pda get b1 --> FAIL
Error: cannot get 'b1': Key not found
$ pda restore --glob c* --file dumpfile --> FAIL
Error: cannot restore '@default': No matches for pattern