refactor(config)!: moved store.list_all_stores to list.list_all_stores
This commit is contained in:
parent
d992074c9c
commit
df70be2c4f
6 changed files with 42 additions and 11 deletions
|
|
@ -219,7 +219,7 @@ pda rm kitty -y
|
|||
|
||||
<p align="center"></p><!-- spacer -->
|
||||
|
||||
`pda ls` to see what you've got stored. By default it lists the contents of all stores. Pass a store name to check only the given store. Checking a specific store is faster than checking everything, but the slowdown should be insignificant unless you have masses of different stores. `store.list_all_stores` can be set to false to list `store.default_store_name` by default.
|
||||
`pda ls` to see what you've got stored. By default it lists the contents of all stores. Pass a store name to check only the given store. Checking a specific store is faster than checking everything, but the slowdown should be insignificant unless you have masses of different stores. `list.list_all_stores` can be set to false to list `store.default_store_name` by default.
|
||||
```bash
|
||||
pda ls
|
||||
# Key Store Value TTL
|
||||
|
|
@ -789,10 +789,13 @@ always_prompt_overwrite = false
|
|||
|
||||
[store]
|
||||
default_store_name = "default"
|
||||
list_all_stores = true
|
||||
always_prompt_delete = true
|
||||
always_prompt_overwrite = true
|
||||
|
||||
[list]
|
||||
list_all_stores = true
|
||||
default_list_format = "table"
|
||||
|
||||
[git]
|
||||
auto_fetch = false
|
||||
auto_commit = true
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type Config struct {
|
|||
DisplayAsciiArt bool `toml:"display_ascii_art"`
|
||||
Key KeyConfig `toml:"key"`
|
||||
Store StoreConfig `toml:"store"`
|
||||
List ListConfig `toml:"list"`
|
||||
Git GitConfig `toml:"git"`
|
||||
}
|
||||
|
||||
|
|
@ -46,11 +47,15 @@ type KeyConfig struct {
|
|||
|
||||
type StoreConfig struct {
|
||||
DefaultStoreName string `toml:"default_store_name"`
|
||||
ListAllStores bool `toml:"list_all_stores"`
|
||||
AlwaysPromptDelete bool `toml:"always_prompt_delete"`
|
||||
AlwaysPromptOverwrite bool `toml:"always_prompt_overwrite"`
|
||||
}
|
||||
|
||||
type ListConfig struct {
|
||||
ListAllStores bool `toml:"list_all_stores"`
|
||||
DefaultListFormat string `toml:"default_list_format"`
|
||||
}
|
||||
|
||||
type GitConfig struct {
|
||||
AutoFetch bool `toml:"auto_fetch"`
|
||||
AutoCommit bool `toml:"auto_commit"`
|
||||
|
|
@ -85,10 +90,13 @@ func defaultConfig() Config {
|
|||
},
|
||||
Store: StoreConfig{
|
||||
DefaultStoreName: "default",
|
||||
ListAllStores: true,
|
||||
AlwaysPromptDelete: true,
|
||||
AlwaysPromptOverwrite: true,
|
||||
},
|
||||
List: ListConfig{
|
||||
ListAllStores: true,
|
||||
DefaultListFormat: "table",
|
||||
},
|
||||
Git: GitConfig{
|
||||
AutoFetch: false,
|
||||
AutoCommit: false,
|
||||
|
|
@ -121,6 +129,13 @@ func loadConfig() (Config, error) {
|
|||
cfg.Store.DefaultStoreName = defaultConfig().Store.DefaultStoreName
|
||||
}
|
||||
|
||||
if cfg.List.DefaultListFormat == "" {
|
||||
cfg.List.DefaultListFormat = defaultConfig().List.DefaultListFormat
|
||||
}
|
||||
if err := validListFormat(cfg.List.DefaultListFormat); err != nil {
|
||||
return cfg, fmt.Errorf("parse %s: list.default_list_format: %w", path, err)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,10 @@ func TestConfigFieldsDottedKeys(t *testing.T) {
|
|||
"key.always_prompt_glob_delete": true,
|
||||
"key.always_prompt_overwrite": true,
|
||||
"store.default_store_name": true,
|
||||
"store.list_all_stores": true,
|
||||
"store.always_prompt_delete": true,
|
||||
"store.always_prompt_overwrite": true,
|
||||
"list.list_all_stores": true,
|
||||
"list.default_list_format": true,
|
||||
"git.auto_fetch": true,
|
||||
"git.auto_commit": true,
|
||||
"git.auto_push": true,
|
||||
|
|
|
|||
17
cmd/list.go
17
cmd/list.go
|
|
@ -46,9 +46,16 @@ type formatEnum string
|
|||
func (e *formatEnum) String() string { return string(*e) }
|
||||
|
||||
func (e *formatEnum) Set(v string) error {
|
||||
if err := validListFormat(v); err != nil {
|
||||
return err
|
||||
}
|
||||
*e = formatEnum(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func validListFormat(v string) error {
|
||||
switch v {
|
||||
case "table", "tsv", "csv", "html", "markdown", "ndjson", "json":
|
||||
*e = formatEnum(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("must be one of 'table', 'tsv', 'csv', 'html', 'markdown', 'ndjson', or 'json'")
|
||||
|
|
@ -66,7 +73,7 @@ var (
|
|||
listFull bool
|
||||
listAll bool
|
||||
listNoHeader bool
|
||||
listFormat formatEnum = "table"
|
||||
listFormat formatEnum
|
||||
|
||||
dimStyle = text.Colors{text.Faint, text.Italic}
|
||||
)
|
||||
|
|
@ -100,6 +107,10 @@ within the same flag.`,
|
|||
}
|
||||
|
||||
func list(cmd *cobra.Command, args []string) error {
|
||||
if listFormat == "" {
|
||||
listFormat = formatEnum(config.List.DefaultListFormat)
|
||||
}
|
||||
|
||||
store := &Store{}
|
||||
|
||||
storePatterns, err := cmd.Flags().GetStringSlice("store")
|
||||
|
|
@ -110,7 +121,7 @@ func list(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("cannot use --store with a store argument")
|
||||
}
|
||||
|
||||
allStores := len(args) == 0 && (config.Store.ListAllStores || listAll)
|
||||
allStores := len(args) == 0 && (config.List.ListAllStores || listAll)
|
||||
var targetDB string
|
||||
if allStores {
|
||||
targetDB = "all"
|
||||
|
|
|
|||
3
testdata/config-list.ct
vendored
3
testdata/config-list.ct
vendored
|
|
@ -4,9 +4,10 @@ key.always_prompt_delete = false
|
|||
key.always_prompt_glob_delete = true
|
||||
key.always_prompt_overwrite = false
|
||||
store.default_store_name = default
|
||||
store.list_all_stores = true
|
||||
store.always_prompt_delete = true
|
||||
store.always_prompt_overwrite = true
|
||||
list.list_all_stores = true
|
||||
list.default_list_format = table
|
||||
git.auto_fetch = false
|
||||
git.auto_commit = false
|
||||
git.auto_push = false
|
||||
|
|
|
|||
4
testdata/help-list.ct
vendored
4
testdata/help-list.ct
vendored
|
|
@ -21,7 +21,7 @@ Flags:
|
|||
-a, --all list across all stores
|
||||
-b, --base64 view binary data as base64
|
||||
-c, --count print only the count of matching entries
|
||||
-o, --format format output format (table|tsv|csv|markdown|html|ndjson|json) (default table)
|
||||
-o, --format format output format (table|tsv|csv|markdown|html|ndjson|json)
|
||||
-f, --full show full values without truncation
|
||||
-h, --help help for list
|
||||
-k, --key strings filter keys with glob pattern (repeatable)
|
||||
|
|
@ -52,7 +52,7 @@ Flags:
|
|||
-a, --all list across all stores
|
||||
-b, --base64 view binary data as base64
|
||||
-c, --count print only the count of matching entries
|
||||
-o, --format format output format (table|tsv|csv|markdown|html|ndjson|json) (default table)
|
||||
-o, --format format output format (table|tsv|csv|markdown|html|ndjson|json)
|
||||
-f, --full show full values without truncation
|
||||
-h, --help help for list
|
||||
-k, --key strings filter keys with glob pattern (repeatable)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue