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
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue