preset glob non-recursive issue; supporting more syntax

This commit is contained in:
2026-05-16 03:41:32 +08:00
parent 3912eed832
commit 615c324d9b
3 changed files with 97 additions and 13 deletions
+36 -2
View File
@@ -1,11 +1,36 @@
package config
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
type StringOrSlice []string
func (s *StringOrSlice) UnmarshalYAML(value *yaml.Node) error {
switch value.Kind {
// "preset: *"
case yaml.ScalarNode:
*s = []string{value.Value}
return nil
// "preset: [a, b]"
case yaml.SequenceNode:
var out []string
for _, v := range value.Content {
out = append(out, v.Value)
}
*s = out
return nil
default:
return fmt.Errorf("invalid preset format")
}
}
type Config struct {
Config struct {
PathMode string `yaml:"path_mode"`
@@ -15,7 +40,7 @@ type Config struct {
Preset string `yaml:"preset"`
} `yaml:"prompts"`
Preset map[string][]string `yaml:"preset"`
Preset map[string]StringOrSlice `yaml:"preset"`
}
func Load() (*Config, error) {
@@ -26,5 +51,14 @@ func Load() (*Config, error) {
var cfg Config
err = yaml.Unmarshal(data, &cfg)
return &cfg, err
if err != nil {
return nil, err
}
// DEFAULT PROMPT TEMPLATE
if cfg.Prompts.Preset == "" {
cfg.Prompts.Preset = "The following code is from file {{path}}:\n---\n{{content}}"
}
return &cfg, nil
}