refactor(branding?): swapped all references to db/dbs to store/stores
This commit is contained in:
parent
9467675715
commit
3d5a3f2aa1
27 changed files with 113 additions and 113 deletions
18
README.md
18
README.md
|
|
@ -31,7 +31,7 @@ and more, written in pure Go, and inspired by [skate](https://github.com/charmbr
|
||||||
|
|
||||||
<p align="center"></p><!-- spacer -->
|
<p align="center"></p><!-- spacer -->
|
||||||
|
|
||||||
`pda!` canonically stores key-value pairs in [badger](https://github.com/dgraph-io/badger) databases for the sake of speed, but supports exporting everything out to a handful of different plaintext formats too, including but not limited to [CSV](https://en.wikipedia.org/wiki/Comma-separated_values), [TSV](https://en.wikipedia.org/wiki/Tab-separated_values), [newline-delimited JSON](https://en.wikipedia.org/wiki/JSON_streaming#Newline-delimited_JSON), and [Markdown](https://en.wikipedia.org/wiki/Markdown) and [HTML](https://en.wikipedia.org/wiki/HTML_element#Tables) tables. `pda!` uses newline-delimited JSON for version control; a full snapshot of every existing key-value pair across all stores can be manually requested with the snapshot command, or auto-commit can be enabled in the config to automatically generate a descriptive commit for every change made.
|
`pda!` canonically stores key-value pairs in [badger](https://github.com/dgraph-io/badger) stores for the sake of speed, but supports exporting everything out to a handful of different plaintext formats too, including but not limited to [CSV](https://en.wikipedia.org/wiki/Comma-separated_values), [TSV](https://en.wikipedia.org/wiki/Tab-separated_values), [newline-delimited JSON](https://en.wikipedia.org/wiki/JSON_streaming#Newline-delimited_JSON), and [Markdown](https://en.wikipedia.org/wiki/Markdown) and [HTML](https://en.wikipedia.org/wiki/HTML_element#Tables) tables. `pda!` uses newline-delimited JSON for version control; a full snapshot of every existing key-value pair across all stores can be manually requested with the snapshot command, or auto-commit can be enabled in the config to automatically generate a descriptive commit for every change made.
|
||||||
|
|
||||||
<p align="center"></p><!-- spacer -->
|
<p align="center"></p><!-- spacer -->
|
||||||
|
|
||||||
|
|
@ -69,10 +69,10 @@ Available Commands:
|
||||||
cp # Copy a value.
|
cp # Copy a value.
|
||||||
mv # Move a value.
|
mv # Move a value.
|
||||||
del # Delete a value.
|
del # Delete a value.
|
||||||
del-db # Delete a whole database.
|
del-store # Delete a whole store.
|
||||||
list-dbs # List all databases.
|
list-stores # List all stores.
|
||||||
dump # Export a database as NDJSON.
|
dump # Export a store as NDJSON.
|
||||||
restore # Imports NDJSON into a database.
|
restore # Imports NDJSON into a store.
|
||||||
init # Initialise or fetch a Git repo for version control.
|
init # Initialise or fetch a Git repo for version control.
|
||||||
sync # Export, commit, pull, restore, and push changes.
|
sync # Export, commit, pull, restore, and push changes.
|
||||||
git # Run git in the pda VCS repository.
|
git # Run git in the pda VCS repository.
|
||||||
|
|
@ -215,11 +215,11 @@ pda restore --glob a* -f my_backup
|
||||||
|
|
||||||
You can have as many stores as you want.
|
You can have as many stores as you want.
|
||||||
```bash
|
```bash
|
||||||
# Save to a spceific store.
|
# Save to a specific store.
|
||||||
pda set alice@birthdays 11/11/1998
|
pda set alice@birthdays 11/11/1998
|
||||||
|
|
||||||
# See which stores have contents.
|
# See which stores have contents.
|
||||||
pda list-dbs
|
pda list-stores
|
||||||
# @default
|
# @default
|
||||||
# @birthdays
|
# @birthdays
|
||||||
|
|
||||||
|
|
@ -235,7 +235,7 @@ pda dump birthdays > friends_birthdays
|
||||||
pda restore birthdays < friends_birthdays
|
pda restore birthdays < friends_birthdays
|
||||||
|
|
||||||
# Delete it.
|
# Delete it.
|
||||||
pda del-db birthdays --force
|
pda del-store birthdays --force
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="center"></p><!-- spacer -->
|
<p align="center"></p><!-- spacer -->
|
||||||
|
|
@ -378,7 +378,7 @@ pda get hello --no-template
|
||||||
|
|
||||||
Globs can be used in a few commands where their use makes sense. `gobwas/glob` is used for matching.
|
Globs can be used in a few commands where their use makes sense. `gobwas/glob` is used for matching.
|
||||||
|
|
||||||
Searching for globs is inherently slower than looking for direct matches, so globs are opt-in via a repeatable `--glob/-g` flag by default rather than having every string treated as a glob by default. Realistically the performance impact will be negligible unless you have many thousands of entries in the same database.
|
Searching for globs is inherently slower than looking for direct matches, so globs are opt-in via a repeatable `--glob/-g` flag by default rather than having every string treated as a glob by default. Realistically the performance impact will be negligible unless you have many thousands of entries in the same store.
|
||||||
|
|
||||||
<p align="center"></p><!-- spacer -->
|
<p align="center"></p><!-- spacer -->
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,43 +31,43 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// delDbCmd represents the set command
|
// delStoreCmd represents the set command
|
||||||
var delDbCmd = &cobra.Command{
|
var delStoreCmd = &cobra.Command{
|
||||||
Use: "del-db DB",
|
Use: "del-store STORE",
|
||||||
Short: "Delete a database",
|
Short: "Delete a store",
|
||||||
Aliases: []string{"delete-db", "rm-db", "remove-db"},
|
Aliases: []string{"delete-store", "rm-store", "remove-store"},
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: delDb,
|
RunE: delStore,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func delDb(cmd *cobra.Command, args []string) error {
|
func delStore(cmd *cobra.Command, args []string) error {
|
||||||
store := &Store{}
|
store := &Store{}
|
||||||
dbName, err := store.parseDB(args[0], false)
|
dbName, err := store.parseDB(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot delete-db '%s': %v", args[0], err)
|
return fmt.Errorf("cannot delete-store '%s': %v", args[0], err)
|
||||||
}
|
}
|
||||||
var notFound errNotFound
|
var notFound errNotFound
|
||||||
path, err := store.FindStore(dbName)
|
path, err := store.FindStore(dbName)
|
||||||
if errors.As(err, ¬Found) {
|
if errors.As(err, ¬Found) {
|
||||||
return fmt.Errorf("cannot delete-db '%s': %v", dbName, err)
|
return fmt.Errorf("cannot delete-store '%s': %v", dbName, err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot delete-db '%s': %v", dbName, err)
|
return fmt.Errorf("cannot delete-store '%s': %v", dbName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
interactive, err := cmd.Flags().GetBool("interactive")
|
interactive, err := cmd.Flags().GetBool("interactive")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot delete-db '%s': %v", dbName, err)
|
return fmt.Errorf("cannot delete-store '%s': %v", dbName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if interactive || config.Store.AlwaysPromptDelete {
|
if interactive || config.Store.AlwaysPromptDelete {
|
||||||
message := fmt.Sprintf("delete-db '%s': are you sure? (y/n)", args[0])
|
message := fmt.Sprintf("delete-store '%s': are you sure? (y/n)", args[0])
|
||||||
fmt.Println(message)
|
fmt.Println(message)
|
||||||
|
|
||||||
var confirm string
|
var confirm string
|
||||||
if _, err := fmt.Scanln(&confirm); err != nil {
|
if _, err := fmt.Scanln(&confirm); err != nil {
|
||||||
return fmt.Errorf("cannot delete-db '%s': %v", dbName, err)
|
return fmt.Errorf("cannot delete-store '%s': %v", dbName, err)
|
||||||
}
|
}
|
||||||
if strings.ToLower(confirm) != "y" {
|
if strings.ToLower(confirm) != "y" {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -81,12 +81,12 @@ func delDb(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
func executeDeletion(path string) error {
|
func executeDeletion(path string) error {
|
||||||
if err := os.RemoveAll(path); err != nil {
|
if err := os.RemoveAll(path); err != nil {
|
||||||
return fmt.Errorf("cannot delete-db '%s': %v", path, err)
|
return fmt.Errorf("cannot delete-store '%s': %v", path, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
delDbCmd.Flags().BoolP("interactive", "i", false, "Prompt yes/no for each deletion")
|
delStoreCmd.Flags().BoolP("interactive", "i", false, "Prompt yes/no for each deletion")
|
||||||
rootCmd.AddCommand(delDbCmd)
|
rootCmd.AddCommand(delStoreCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import (
|
||||||
|
|
||||||
// delCmd represents the set command
|
// delCmd represents the set command
|
||||||
var delCmd = &cobra.Command{
|
var delCmd = &cobra.Command{
|
||||||
Use: "del KEY[@DB] [KEY[@DB] ...]",
|
Use: "del KEY[@STORE] [KEY[@STORE] ...]",
|
||||||
Short: "Delete one or more keys",
|
Short: "Delete one or more keys",
|
||||||
Aliases: []string{"delete", "rm", "remove"},
|
Aliases: []string{"delete", "rm", "remove"},
|
||||||
Args: cobra.ArbitraryArgs,
|
Args: cobra.ArbitraryArgs,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ type dumpEntry struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var dumpCmd = &cobra.Command{
|
var dumpCmd = &cobra.Command{
|
||||||
Use: "dump [DB]",
|
Use: "dump [STORE]",
|
||||||
Short: "Dump all key/value pairs as NDJSON",
|
Short: "Dump all key/value pairs as NDJSON",
|
||||||
Aliases: []string{"export"},
|
Aliases: []string{"export"},
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
|
@ -130,7 +130,7 @@ func encodeText(entry *dumpEntry, key []byte, v []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpOptions controls how a database is dumped to NDJSON.
|
// DumpOptions controls how a store is dumped to NDJSON.
|
||||||
type DumpOptions struct {
|
type DumpOptions struct {
|
||||||
Encoding string
|
Encoding string
|
||||||
IncludeSecret bool
|
IncludeSecret bool
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ import (
|
||||||
|
|
||||||
// getCmd represents the get command
|
// getCmd represents the get command
|
||||||
var getCmd = &cobra.Command{
|
var getCmd = &cobra.Command{
|
||||||
Use: "get KEY[@DB]",
|
Use: "get KEY[@STORE]",
|
||||||
Short: "Get the value of a key",
|
Short: "Get the value of a key",
|
||||||
Long: `Get the value of a key. Optionally specify a db.
|
Long: `Get the value of a key. Optionally specify a store.
|
||||||
|
|
||||||
{{ .TEMPLATES }} can be filled by passing TEMPLATE=VALUE as an
|
{{ .TEMPLATES }} can be filled by passing TEMPLATE=VALUE as an
|
||||||
additional argument after the initial KEY being fetched.
|
additional argument after the initial KEY being fetched.
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ import (
|
||||||
var gitCmd = &cobra.Command{
|
var gitCmd = &cobra.Command{
|
||||||
Use: "git [args...]",
|
Use: "git [args...]",
|
||||||
Short: "Run any arbitrary command. Use with caution.",
|
Short: "Run any arbitrary command. Use with caution.",
|
||||||
Long: `Run any arbitrary command. Use with caution.
|
Long: `Run any arbitrary command. Use with caution.
|
||||||
|
|
||||||
Be wary of how pda! version control operates before using this. Regular data is stored in "PDA_DATA/pda/stores" as a database; the Git repository is in "PDA_DATA/pda/vcs" and contains a replica of the database stored as plaintext.
|
Be wary of how pda! version control operates before using this. Regular data is stored in "PDA_DATA/pda/stores" as a store; the Git repository is in "PDA_DATA/pda/vcs" and contains a plaintext replica of the store data.
|
||||||
|
|
||||||
The regular sync command (or auto-syncing) exports pda! data into plaintext in the Git repository. If you manually modify the repository without using the built-in commands, or exporting your data to the folder in the correct format first, you may desynchronize your repository.`,
|
The regular sync command (or auto-syncing) exports pda! data into plaintext in the Git repository. If you manually modify the repository without using the built-in commands, or exporting your data to the folder in the correct format first, you may desynchronize your repository.`,
|
||||||
Args: cobra.ArbitraryArgs,
|
Args: cobra.ArbitraryArgs,
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,17 @@ import (
|
||||||
type KeySpec struct {
|
type KeySpec struct {
|
||||||
Raw string // Whole, unmodified user input
|
Raw string // Whole, unmodified user input
|
||||||
RawKey string // Key segment
|
RawKey string // Key segment
|
||||||
RawDB string // DB segment
|
RawDB string // Store segment
|
||||||
Key string // Normalised Key
|
Key string // Normalised Key
|
||||||
DB string // Normalised DB
|
DB string // Normalised store
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseKey parses "KEY[@DB]" into a normalized KeySpec.
|
// ParseKey parses "KEY[@STORE]" into a normalized KeySpec.
|
||||||
// When defaults is true, a missing DB defaults to the configured default.
|
// When defaults is true, a missing store defaults to the configured default.
|
||||||
func ParseKey(raw string, defaults bool) (KeySpec, error) {
|
func ParseKey(raw string, defaults bool) (KeySpec, error) {
|
||||||
parts := strings.Split(raw, "@")
|
parts := strings.Split(raw, "@")
|
||||||
if len(parts) > 2 {
|
if len(parts) > 2 {
|
||||||
return KeySpec{}, fmt.Errorf("bad key format, use KEY@DB")
|
return KeySpec{}, fmt.Errorf("bad key format, use KEY@STORE")
|
||||||
}
|
}
|
||||||
|
|
||||||
rawKey := parts[0]
|
rawKey := parts[0]
|
||||||
|
|
@ -49,7 +49,7 @@ func ParseKey(raw string, defaults bool) (KeySpec, error) {
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
rawDB = parts[1]
|
rawDB = parts[1]
|
||||||
if strings.TrimSpace(rawDB) == "" {
|
if strings.TrimSpace(rawDB) == "" {
|
||||||
return KeySpec{}, fmt.Errorf("bad key format, use KEY@DB")
|
return KeySpec{}, fmt.Errorf("bad key format, use KEY@STORE")
|
||||||
}
|
}
|
||||||
if err := validateDBName(rawDB); err != nil {
|
if err := validateDBName(rawDB); err != nil {
|
||||||
return KeySpec{}, err
|
return KeySpec{}, err
|
||||||
|
|
@ -80,7 +80,7 @@ func (k KeySpec) Full() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display returns the normalized key reference
|
// Display returns the normalized key reference
|
||||||
// but omits the default database if none was set manually
|
// but omits the default store if none was set manually
|
||||||
func (k KeySpec) Display() string {
|
func (k KeySpec) Display() string {
|
||||||
if k.DB == "" || k.DB == config.Store.DefaultStoreName {
|
if k.DB == "" || k.DB == config.Store.DefaultStoreName {
|
||||||
return k.Key
|
return k.Key
|
||||||
|
|
|
||||||
|
|
@ -28,20 +28,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// delCmd represents the set command
|
// delCmd represents the set command
|
||||||
var listDbsCmd = &cobra.Command{
|
var listStoresCmd = &cobra.Command{
|
||||||
Use: "list-dbs",
|
Use: "list-stores",
|
||||||
Short: "List all databases",
|
Short: "List all stores",
|
||||||
Aliases: []string{"ls-dbs", "lsd"},
|
Aliases: []string{"ls-stores", "lsd"},
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: listDbs,
|
RunE: listStores,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func listDbs(cmd *cobra.Command, args []string) error {
|
func listStores(cmd *cobra.Command, args []string) error {
|
||||||
store := &Store{}
|
store := &Store{}
|
||||||
dbs, err := store.AllStores()
|
dbs, err := store.AllStores()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot list-dbs: %v", err)
|
return fmt.Errorf("cannot list-stores: %v", err)
|
||||||
}
|
}
|
||||||
for _, db := range dbs {
|
for _, db := range dbs {
|
||||||
fmt.Println("@" + db)
|
fmt.Println("@" + db)
|
||||||
|
|
@ -50,5 +50,5 @@ func listDbs(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(listDbsCmd)
|
rootCmd.AddCommand(listStoresCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var listCmd = &cobra.Command{
|
var listCmd = &cobra.Command{
|
||||||
Use: "list [DB]",
|
Use: "list [STORE]",
|
||||||
Short: "List the contents of a database",
|
Short: "List the contents of a store",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: list,
|
RunE: list,
|
||||||
|
|
@ -52,7 +52,7 @@ func list(cmd *cobra.Command, args []string) error {
|
||||||
if _, err := store.FindStore(dbName); err != nil {
|
if _, err := store.FindStore(dbName); err != nil {
|
||||||
var notFound errNotFound
|
var notFound errNotFound
|
||||||
if errors.As(err, ¬Found) {
|
if errors.As(err, ¬Found) {
|
||||||
return fmt.Errorf("cannot ls '%s': No such DB", args[0])
|
return fmt.Errorf("cannot ls '%s': No such store", args[0])
|
||||||
}
|
}
|
||||||
return fmt.Errorf("cannot ls '%s': %v", args[0], err)
|
return fmt.Errorf("cannot ls '%s': %v", args[0], err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var cpCmd = &cobra.Command{
|
var cpCmd = &cobra.Command{
|
||||||
Use: "cp FROM[@DB] TO[@DB]",
|
Use: "cp FROM[@STORE] TO[@STORE]",
|
||||||
Short: "Make a copy of a key",
|
Short: "Make a copy of a key",
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: cp,
|
RunE: cp,
|
||||||
}
|
}
|
||||||
|
|
||||||
var mvCmd = &cobra.Command{
|
var mvCmd = &cobra.Command{
|
||||||
Use: "mv FROM[@DB] TO[@DB]",
|
Use: "mv FROM[@STORE] TO[@STORE]",
|
||||||
Short: "Move a key",
|
Short: "Move a key",
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: mv,
|
RunE: mv,
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var restoreCmd = &cobra.Command{
|
var restoreCmd = &cobra.Command{
|
||||||
Use: "restore [DB]",
|
Use: "restore [STORE]",
|
||||||
Short: "Restore key/value pairs from an NDJSON dump",
|
Short: "Restore key/value pairs from an NDJSON dump",
|
||||||
Aliases: []string{"import"},
|
Aliases: []string{"import"},
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ import (
|
||||||
|
|
||||||
// setCmd represents the set command
|
// setCmd represents the set command
|
||||||
var setCmd = &cobra.Command{
|
var setCmd = &cobra.Command{
|
||||||
Use: "set KEY[@DB] [VALUE]",
|
Use: "set KEY[@STORE] [VALUE]",
|
||||||
Short: "Set a key to a given value",
|
Short: "Set a key to a given value",
|
||||||
Long: `Set a key to a given value or stdin. Optionally specify a db.
|
Long: `Set a key to a given value or stdin. Optionally specify a store.
|
||||||
|
|
||||||
PDA supports parsing Go templates. Actions are delimited with {{ }}.
|
PDA supports parsing Go templates. Actions are delimited with {{ }}.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,10 +176,10 @@ func (s *Store) parseDB(v string, defaults bool) (string, error) {
|
||||||
if defaults {
|
if defaults {
|
||||||
return config.Store.DefaultStoreName, nil
|
return config.Store.DefaultStoreName, nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("cannot parse db: bad db format, use DB or @DB")
|
return "", fmt.Errorf("cannot parse store: bad store format, use STORE or @STORE")
|
||||||
}
|
}
|
||||||
if err := validateDBName(db); err != nil {
|
if err := validateDBName(db); err != nil {
|
||||||
return "", fmt.Errorf("cannot parse db: %w", err)
|
return "", fmt.Errorf("cannot parse store: %w", err)
|
||||||
}
|
}
|
||||||
return strings.ToLower(db), nil
|
return strings.ToLower(db), nil
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +262,7 @@ func ensureSubpath(base, target string) error {
|
||||||
|
|
||||||
func validateDBName(name string) error {
|
func validateDBName(name string) error {
|
||||||
if strings.ContainsAny(name, `/\~`) {
|
if strings.ContainsAny(name, `/\~`) {
|
||||||
return fmt.Errorf("bad db format, use DB or @DB")
|
return fmt.Errorf("bad store format, use STORE or @STORE")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -279,7 +279,7 @@ func formatExpiry(expiresAt uint64) string {
|
||||||
return fmt.Sprintf("%s (in %s)", expiry.Format(time.RFC3339), remaining.Round(time.Second))
|
return fmt.Sprintf("%s (in %s)", expiry.Format(time.RFC3339), remaining.Round(time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys returns all keys for the provided database name (or default if empty).
|
// Keys returns all keys for the provided store name (or default if empty).
|
||||||
// Keys are returned in lowercase to mirror stored key format.
|
// Keys are returned in lowercase to mirror stored key format.
|
||||||
func (s *Store) Keys(dbName string) ([]string, error) {
|
func (s *Store) Keys(dbName string) ([]string, error) {
|
||||||
db, err := s.open(dbName)
|
db, err := s.open(dbName)
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ func snapshotDB(store *Store, repoDir, db string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// exportAllStores writes every Badger store to ndjson files under repoDir/stores
|
// exportAllStores writes every Badger store to ndjson files under repoDir/stores
|
||||||
// and removes stale snapshot files for deleted databases.
|
// and removes stale snapshot files for deleted stores.
|
||||||
func exportAllStores(store *Store, repoDir string) error {
|
func exportAllStores(store *Store, repoDir string) error {
|
||||||
stores, err := store.AllStores()
|
stores, err := store.AllStores()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -335,7 +335,7 @@ func restoreAllSnapshots(store *Store, repoDir string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := os.RemoveAll(dbPath); err != nil {
|
if err := os.RemoveAll(dbPath); err != nil {
|
||||||
return fmt.Errorf("remove db '%s': %w", db, err)
|
return fmt.Errorf("remove store '%s': %w", db, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,7 +353,7 @@ func wipeAllStores(store *Store) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := os.RemoveAll(path); err != nil {
|
if err := os.RemoveAll(path); err != nil {
|
||||||
return fmt.Errorf("remove db '%s': %w", db, err)
|
return fmt.Errorf("remove store '%s': %w", db, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
4
testdata/del-db__err__with__invalid_db.ct
vendored
4
testdata/del-db__err__with__invalid_db.ct
vendored
|
|
@ -1,2 +1,2 @@
|
||||||
$ pda del-db foo/bar --> FAIL
|
$ pda del-store foo/bar --> FAIL
|
||||||
Error: cannot delete-db 'foo/bar': cannot parse db: bad db format, use DB or @DB
|
Error: cannot delete-store 'foo/bar': cannot parse store: bad store format, use STORE or @STORE
|
||||||
|
|
|
||||||
2
testdata/get__err__with__invalid_db.ct
vendored
2
testdata/get__err__with__invalid_db.ct
vendored
|
|
@ -1,2 +1,2 @@
|
||||||
$ pda get key@foo/bar --> FAIL
|
$ pda get key@foo/bar --> FAIL
|
||||||
Error: cannot get 'key@foo/bar': bad db format, use DB or @DB
|
Error: cannot get 'key@foo/bar': bad store format, use STORE or @STORE
|
||||||
|
|
|
||||||
20
testdata/help__del-db__ok.ct
vendored
20
testdata/help__del-db__ok.ct
vendored
|
|
@ -1,24 +1,24 @@
|
||||||
$ pda help del-db
|
$ pda help del-store
|
||||||
$ pda del-db --help
|
$ pda del-store --help
|
||||||
Delete a database
|
Delete a store
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda del-db DB [flags]
|
pda del-store STORE [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
del-db, delete-db, rm-db, remove-db
|
del-store, delete-store, rm-store, remove-store
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for del-db
|
-h, --help help for del-store
|
||||||
-i, --interactive Prompt yes/no for each deletion
|
-i, --interactive Prompt yes/no for each deletion
|
||||||
Delete a database
|
Delete a store
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda del-db DB [flags]
|
pda del-store STORE [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
del-db, delete-db, rm-db, remove-db
|
del-store, delete-store, rm-store, remove-store
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for del-db
|
-h, --help help for del-store
|
||||||
-i, --interactive Prompt yes/no for each deletion
|
-i, --interactive Prompt yes/no for each deletion
|
||||||
|
|
|
||||||
4
testdata/help__del__ok.ct
vendored
4
testdata/help__del__ok.ct
vendored
|
|
@ -3,7 +3,7 @@ $ pda del --help
|
||||||
Delete one or more keys
|
Delete one or more keys
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda del KEY[@DB] [KEY[@DB] ...] [flags]
|
pda del KEY[@STORE] [KEY[@STORE] ...] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
del, delete, rm, remove
|
del, delete, rm, remove
|
||||||
|
|
@ -16,7 +16,7 @@ Flags:
|
||||||
Delete one or more keys
|
Delete one or more keys
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda del KEY[@DB] [KEY[@DB] ...] [flags]
|
pda del KEY[@STORE] [KEY[@STORE] ...] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
del, delete, rm, remove
|
del, delete, rm, remove
|
||||||
|
|
|
||||||
4
testdata/help__dump__ok.ct
vendored
4
testdata/help__dump__ok.ct
vendored
|
|
@ -3,7 +3,7 @@ $ pda dump --help
|
||||||
Dump all key/value pairs as NDJSON
|
Dump all key/value pairs as NDJSON
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda dump [DB] [flags]
|
pda dump [STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
dump, export
|
dump, export
|
||||||
|
|
@ -17,7 +17,7 @@ Flags:
|
||||||
Dump all key/value pairs as NDJSON
|
Dump all key/value pairs as NDJSON
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda dump [DB] [flags]
|
pda dump [STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
dump, export
|
dump, export
|
||||||
|
|
|
||||||
8
testdata/help__get__ok.ct
vendored
8
testdata/help__get__ok.ct
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
$ pda help get
|
$ pda help get
|
||||||
$ pda get --help
|
$ pda get --help
|
||||||
Get the value of a key. Optionally specify a db.
|
Get the value of a key. Optionally specify a store.
|
||||||
|
|
||||||
{{ .TEMPLATES }} can be filled by passing TEMPLATE=VALUE as an
|
{{ .TEMPLATES }} can be filled by passing TEMPLATE=VALUE as an
|
||||||
additional argument after the initial KEY being fetched.
|
additional argument after the initial KEY being fetched.
|
||||||
|
|
@ -10,7 +10,7 @@ For example:
|
||||||
pda get greeting NAME=World
|
pda get greeting NAME=World
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda get KEY[@DB] [flags]
|
pda get KEY[@STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
get, g
|
get, g
|
||||||
|
|
@ -21,7 +21,7 @@ Flags:
|
||||||
--no-template directly output template syntax
|
--no-template directly output template syntax
|
||||||
-c, --run execute the result as a shell command
|
-c, --run execute the result as a shell command
|
||||||
--secret display values marked as secret
|
--secret display values marked as secret
|
||||||
Get the value of a key. Optionally specify a db.
|
Get the value of a key. Optionally specify a store.
|
||||||
|
|
||||||
{{ .TEMPLATES }} can be filled by passing TEMPLATE=VALUE as an
|
{{ .TEMPLATES }} can be filled by passing TEMPLATE=VALUE as an
|
||||||
additional argument after the initial KEY being fetched.
|
additional argument after the initial KEY being fetched.
|
||||||
|
|
@ -31,7 +31,7 @@ For example:
|
||||||
pda get greeting NAME=World
|
pda get greeting NAME=World
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda get KEY[@DB] [flags]
|
pda get KEY[@STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
get, g
|
get, g
|
||||||
|
|
|
||||||
20
testdata/help__list-dbs__ok.ct
vendored
20
testdata/help__list-dbs__ok.ct
vendored
|
|
@ -1,22 +1,22 @@
|
||||||
$ pda help list-dbs
|
$ pda help list-stores
|
||||||
$ pda list-dbs --help
|
$ pda list-stores --help
|
||||||
List all databases
|
List all stores
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda list-dbs [flags]
|
pda list-stores [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
list-dbs, ls-dbs, lsd
|
list-stores, ls-stores, lsd
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for list-dbs
|
-h, --help help for list-stores
|
||||||
List all databases
|
List all stores
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda list-dbs [flags]
|
pda list-stores [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
list-dbs, ls-dbs, lsd
|
list-stores, ls-stores, lsd
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for list-dbs
|
-h, --help help for list-stores
|
||||||
|
|
|
||||||
8
testdata/help__list__ok.ct
vendored
8
testdata/help__list__ok.ct
vendored
|
|
@ -1,9 +1,9 @@
|
||||||
$ pda help list
|
$ pda help list
|
||||||
$ pda list --help
|
$ pda list --help
|
||||||
List the contents of a database
|
List the contents of a store
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda list [DB] [flags]
|
pda list [STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
list, ls
|
list, ls
|
||||||
|
|
@ -19,10 +19,10 @@ Flags:
|
||||||
--no-values suppress the value column
|
--no-values suppress the value column
|
||||||
-S, --secret display values marked as secret
|
-S, --secret display values marked as secret
|
||||||
-t, --ttl append a TTL column when entries expire
|
-t, --ttl append a TTL column when entries expire
|
||||||
List the contents of a database
|
List the contents of a store
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda list [DB] [flags]
|
pda list [STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
list, ls
|
list, ls
|
||||||
|
|
|
||||||
12
testdata/help__ok.ct
vendored
12
testdata/help__ok.ct
vendored
|
|
@ -16,14 +16,14 @@ Available Commands:
|
||||||
completion Generate the autocompletion script for the specified shell
|
completion Generate the autocompletion script for the specified shell
|
||||||
cp Make a copy of a key
|
cp Make a copy of a key
|
||||||
del Delete one or more keys
|
del Delete one or more keys
|
||||||
del-db Delete a database
|
del-store Delete a store
|
||||||
dump Dump all key/value pairs as NDJSON
|
dump Dump all key/value pairs as NDJSON
|
||||||
get Get the value of a key
|
get Get the value of a key
|
||||||
git Run any arbitrary command. Use with caution.
|
git Run any arbitrary command. Use with caution.
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialise pda! version control
|
init Initialise pda! version control
|
||||||
list List the contents of a database
|
list List the contents of a store
|
||||||
list-dbs List all databases
|
list-stores List all stores
|
||||||
mv Move a key
|
mv Move a key
|
||||||
restore Restore key/value pairs from an NDJSON dump
|
restore Restore key/value pairs from an NDJSON dump
|
||||||
set Set a key to a given value
|
set Set a key to a given value
|
||||||
|
|
@ -50,14 +50,14 @@ Available Commands:
|
||||||
completion Generate the autocompletion script for the specified shell
|
completion Generate the autocompletion script for the specified shell
|
||||||
cp Make a copy of a key
|
cp Make a copy of a key
|
||||||
del Delete one or more keys
|
del Delete one or more keys
|
||||||
del-db Delete a database
|
del-store Delete a store
|
||||||
dump Dump all key/value pairs as NDJSON
|
dump Dump all key/value pairs as NDJSON
|
||||||
get Get the value of a key
|
get Get the value of a key
|
||||||
git Run any arbitrary command. Use with caution.
|
git Run any arbitrary command. Use with caution.
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialise pda! version control
|
init Initialise pda! version control
|
||||||
list List the contents of a database
|
list List the contents of a store
|
||||||
list-dbs List all databases
|
list-stores List all stores
|
||||||
mv Move a key
|
mv Move a key
|
||||||
restore Restore key/value pairs from an NDJSON dump
|
restore Restore key/value pairs from an NDJSON dump
|
||||||
set Set a key to a given value
|
set Set a key to a given value
|
||||||
|
|
|
||||||
4
testdata/help__restore__ok.ct
vendored
4
testdata/help__restore__ok.ct
vendored
|
|
@ -3,7 +3,7 @@ $ pda restore --help
|
||||||
Restore key/value pairs from an NDJSON dump
|
Restore key/value pairs from an NDJSON dump
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda restore [DB] [flags]
|
pda restore [STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
restore, import
|
restore, import
|
||||||
|
|
@ -17,7 +17,7 @@ Flags:
|
||||||
Restore key/value pairs from an NDJSON dump
|
Restore key/value pairs from an NDJSON dump
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda restore [DB] [flags]
|
pda restore [STORE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
restore, import
|
restore, import
|
||||||
|
|
|
||||||
8
testdata/help__set__ok.ct
vendored
8
testdata/help__set__ok.ct
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
$ pda help set
|
$ pda help set
|
||||||
$ pda set --help
|
$ pda set --help
|
||||||
Set a key to a given value or stdin. Optionally specify a db.
|
Set a key to a given value or stdin. Optionally specify a store.
|
||||||
|
|
||||||
PDA supports parsing Go templates. Actions are delimited with {{ }}.
|
PDA supports parsing Go templates. Actions are delimited with {{ }}.
|
||||||
|
|
||||||
|
|
@ -12,7 +12,7 @@ For example:
|
||||||
'{{ enum .NAME "Alice" "Bob" }}' allows only NAME=Alice or NAME=Bob.
|
'{{ enum .NAME "Alice" "Bob" }}' allows only NAME=Alice or NAME=Bob.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda set KEY[@DB] [VALUE] [flags]
|
pda set KEY[@STORE] [VALUE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
set, s
|
set, s
|
||||||
|
|
@ -22,7 +22,7 @@ Flags:
|
||||||
-i, --interactive Prompt before overwriting an existing key
|
-i, --interactive Prompt before overwriting an existing key
|
||||||
--secret Mark the stored value as a secret
|
--secret Mark the stored value as a secret
|
||||||
-t, --ttl duration Expire the key after the provided duration (e.g. 24h, 30m)
|
-t, --ttl duration Expire the key after the provided duration (e.g. 24h, 30m)
|
||||||
Set a key to a given value or stdin. Optionally specify a db.
|
Set a key to a given value or stdin. Optionally specify a store.
|
||||||
|
|
||||||
PDA supports parsing Go templates. Actions are delimited with {{ }}.
|
PDA supports parsing Go templates. Actions are delimited with {{ }}.
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ For example:
|
||||||
'{{ enum .NAME "Alice" "Bob" }}' allows only NAME=Alice or NAME=Bob.
|
'{{ enum .NAME "Alice" "Bob" }}' allows only NAME=Alice or NAME=Bob.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
pda set KEY[@DB] [VALUE] [flags]
|
pda set KEY[@STORE] [VALUE] [flags]
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
set, s
|
set, s
|
||||||
|
|
|
||||||
2
testdata/list__err__with__invalid_db.ct
vendored
2
testdata/list__err__with__invalid_db.ct
vendored
|
|
@ -1,2 +1,2 @@
|
||||||
$ pda ls foo/bar --> FAIL
|
$ pda ls foo/bar --> FAIL
|
||||||
Error: cannot ls 'foo/bar': cannot parse db: bad db format, use DB or @DB
|
Error: cannot ls 'foo/bar': cannot parse store: bad store format, use STORE or @STORE
|
||||||
|
|
|
||||||
6
testdata/root__ok.ct
vendored
6
testdata/root__ok.ct
vendored
|
|
@ -15,14 +15,14 @@ Available Commands:
|
||||||
completion Generate the autocompletion script for the specified shell
|
completion Generate the autocompletion script for the specified shell
|
||||||
cp Make a copy of a key
|
cp Make a copy of a key
|
||||||
del Delete one or more keys
|
del Delete one or more keys
|
||||||
del-db Delete a database
|
del-store Delete a store
|
||||||
dump Dump all key/value pairs as NDJSON
|
dump Dump all key/value pairs as NDJSON
|
||||||
get Get the value of a key
|
get Get the value of a key
|
||||||
git Run any arbitrary command. Use with caution.
|
git Run any arbitrary command. Use with caution.
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialise pda! version control
|
init Initialise pda! version control
|
||||||
list List the contents of a database
|
list List the contents of a store
|
||||||
list-dbs List all databases
|
list-stores List all stores
|
||||||
mv Move a key
|
mv Move a key
|
||||||
restore Restore key/value pairs from an NDJSON dump
|
restore Restore key/value pairs from an NDJSON dump
|
||||||
set Set a key to a given value
|
set Set a key to a given value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue