refactor(branding?): swapped all references to db/dbs to store/stores

This commit is contained in:
Lewis Wynne 2025-12-23 09:07:45 +00:00
parent 9467675715
commit 3d5a3f2aa1
27 changed files with 113 additions and 113 deletions

View file

@ -31,43 +31,43 @@ import (
"github.com/spf13/cobra"
)
// delDbCmd represents the set command
var delDbCmd = &cobra.Command{
Use: "del-db DB",
Short: "Delete a database",
Aliases: []string{"delete-db", "rm-db", "remove-db"},
// delStoreCmd represents the set command
var delStoreCmd = &cobra.Command{
Use: "del-store STORE",
Short: "Delete a store",
Aliases: []string{"delete-store", "rm-store", "remove-store"},
Args: cobra.ExactArgs(1),
RunE: delDb,
RunE: delStore,
SilenceUsage: true,
}
func delDb(cmd *cobra.Command, args []string) error {
func delStore(cmd *cobra.Command, args []string) error {
store := &Store{}
dbName, err := store.parseDB(args[0], false)
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
path, err := store.FindStore(dbName)
if errors.As(err, &notFound) {
return fmt.Errorf("cannot delete-db '%s': %v", dbName, err)
return fmt.Errorf("cannot delete-store '%s': %v", dbName, err)
}
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")
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 {
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)
var confirm string
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" {
return nil
@ -81,12 +81,12 @@ func delDb(cmd *cobra.Command, args []string) error {
func executeDeletion(path string) error {
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
}
func init() {
delDbCmd.Flags().BoolP("interactive", "i", false, "Prompt yes/no for each deletion")
rootCmd.AddCommand(delDbCmd)
delStoreCmd.Flags().BoolP("interactive", "i", false, "Prompt yes/no for each deletion")
rootCmd.AddCommand(delStoreCmd)
}

View file

@ -34,7 +34,7 @@ import (
// delCmd represents the set command
var delCmd = &cobra.Command{
Use: "del KEY[@DB] [KEY[@DB] ...]",
Use: "del KEY[@STORE] [KEY[@STORE] ...]",
Short: "Delete one or more keys",
Aliases: []string{"delete", "rm", "remove"},
Args: cobra.ArbitraryArgs,

View file

@ -45,7 +45,7 @@ type dumpEntry struct {
}
var dumpCmd = &cobra.Command{
Use: "dump [DB]",
Use: "dump [STORE]",
Short: "Dump all key/value pairs as NDJSON",
Aliases: []string{"export"},
Args: cobra.MaximumNArgs(1),
@ -130,7 +130,7 @@ func encodeText(entry *dumpEntry, key []byte, v []byte) error {
return nil
}
// DumpOptions controls how a database is dumped to NDJSON.
// DumpOptions controls how a store is dumped to NDJSON.
type DumpOptions struct {
Encoding string
IncludeSecret bool

View file

@ -38,9 +38,9 @@ import (
// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get KEY[@DB]",
Use: "get KEY[@STORE]",
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
additional argument after the initial KEY being fetched.

View file

@ -32,9 +32,9 @@ import (
var gitCmd = &cobra.Command{
Use: "git [args...]",
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.`,
Args: cobra.ArbitraryArgs,

View file

@ -31,17 +31,17 @@ import (
type KeySpec struct {
Raw string // Whole, unmodified user input
RawKey string // Key segment
RawDB string // DB segment
RawDB string // Store segment
Key string // Normalised Key
DB string // Normalised DB
DB string // Normalised store
}
// ParseKey parses "KEY[@DB]" into a normalized KeySpec.
// When defaults is true, a missing DB defaults to the configured default.
// ParseKey parses "KEY[@STORE]" into a normalized KeySpec.
// When defaults is true, a missing store defaults to the configured default.
func ParseKey(raw string, defaults bool) (KeySpec, error) {
parts := strings.Split(raw, "@")
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]
@ -49,7 +49,7 @@ func ParseKey(raw string, defaults bool) (KeySpec, error) {
if len(parts) == 2 {
rawDB = parts[1]
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 {
return KeySpec{}, err
@ -80,7 +80,7 @@ func (k KeySpec) Full() string {
}
// 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 {
if k.DB == "" || k.DB == config.Store.DefaultStoreName {
return k.Key

View file

@ -28,20 +28,20 @@ import (
)
// delCmd represents the set command
var listDbsCmd = &cobra.Command{
Use: "list-dbs",
Short: "List all databases",
Aliases: []string{"ls-dbs", "lsd"},
var listStoresCmd = &cobra.Command{
Use: "list-stores",
Short: "List all stores",
Aliases: []string{"ls-stores", "lsd"},
Args: cobra.NoArgs,
RunE: listDbs,
RunE: listStores,
SilenceUsage: true,
}
func listDbs(cmd *cobra.Command, args []string) error {
func listStores(cmd *cobra.Command, args []string) error {
store := &Store{}
dbs, err := store.AllStores()
if err != nil {
return fmt.Errorf("cannot list-dbs: %v", err)
return fmt.Errorf("cannot list-stores: %v", err)
}
for _, db := range dbs {
fmt.Println("@" + db)
@ -50,5 +50,5 @@ func listDbs(cmd *cobra.Command, args []string) error {
}
func init() {
rootCmd.AddCommand(listDbsCmd)
rootCmd.AddCommand(listStoresCmd)
}

View file

@ -32,8 +32,8 @@ import (
)
var listCmd = &cobra.Command{
Use: "list [DB]",
Short: "List the contents of a database",
Use: "list [STORE]",
Short: "List the contents of a store",
Aliases: []string{"ls"},
Args: cobra.MaximumNArgs(1),
RunE: list,
@ -52,7 +52,7 @@ func list(cmd *cobra.Command, args []string) error {
if _, err := store.FindStore(dbName); err != nil {
var notFound errNotFound
if errors.As(err, &notFound) {
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)
}

View file

@ -31,14 +31,14 @@ import (
)
var cpCmd = &cobra.Command{
Use: "cp FROM[@DB] TO[@DB]",
Use: "cp FROM[@STORE] TO[@STORE]",
Short: "Make a copy of a key",
Args: cobra.ExactArgs(2),
RunE: cp,
}
var mvCmd = &cobra.Command{
Use: "mv FROM[@DB] TO[@DB]",
Use: "mv FROM[@STORE] TO[@STORE]",
Short: "Move a key",
Args: cobra.ExactArgs(2),
RunE: mv,

View file

@ -36,7 +36,7 @@ import (
)
var restoreCmd = &cobra.Command{
Use: "restore [DB]",
Use: "restore [STORE]",
Short: "Restore key/value pairs from an NDJSON dump",
Aliases: []string{"import"},
Args: cobra.MaximumNArgs(1),

View file

@ -33,9 +33,9 @@ import (
// setCmd represents the set command
var setCmd = &cobra.Command{
Use: "set KEY[@DB] [VALUE]",
Use: "set KEY[@STORE] [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 {{ }}.

View file

@ -176,10 +176,10 @@ func (s *Store) parseDB(v string, defaults bool) (string, error) {
if defaults {
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 {
return "", fmt.Errorf("cannot parse db: %w", err)
return "", fmt.Errorf("cannot parse store: %w", err)
}
return strings.ToLower(db), nil
}
@ -262,7 +262,7 @@ func ensureSubpath(base, target string) error {
func validateDBName(name string) error {
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
}
@ -279,7 +279,7 @@ func formatExpiry(expiresAt uint64) string {
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.
func (s *Store) Keys(dbName string) ([]string, error) {
db, err := s.open(dbName)

View file

@ -93,7 +93,7 @@ func snapshotDB(store *Store, repoDir, db string) error {
}
// 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 {
stores, err := store.AllStores()
if err != nil {
@ -335,7 +335,7 @@ func restoreAllSnapshots(store *Store, repoDir string) error {
return err
}
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
}
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