fix: write startup config keys to config.yaml instead of SQLite (GH#536)
`bd config set no-db true` now correctly writes to config.yaml instead of SQLite. Previously, startup flags like no-db, no-daemon, no-auto-flush were stored in SQLite but read from config.yaml at startup - making the command appear to work while having no effect. This adds: - yaml_config.go: Defines yaml-only keys and provides SetYamlConfig/GetYamlConfig - Updated config set/get commands to route yaml-only keys appropriately - Comprehensive tests for yaml config handling Startup flags affected: no-db, no-daemon, no-auto-flush, no-auto-import, json, auto-start-daemon, flush-debounce, lock-timeout, git.*, sync.*, routing.* 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/syncbranch"
|
||||
)
|
||||
|
||||
@@ -49,17 +50,38 @@ var configSetCmd = &cobra.Command{
|
||||
Short: "Set a configuration value",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
// Config operations work in direct mode only
|
||||
key := args[0]
|
||||
value := args[1]
|
||||
|
||||
// Check if this is a yaml-only key (startup settings like no-db, no-daemon, etc.)
|
||||
// These must be written to config.yaml, not SQLite, because they're read
|
||||
// before the database is opened. (GH#536)
|
||||
if config.IsYamlOnlyKey(key) {
|
||||
if err := config.SetYamlConfig(key, value); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error setting config: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(map[string]interface{}{
|
||||
"key": key,
|
||||
"value": value,
|
||||
"location": "config.yaml",
|
||||
})
|
||||
} else {
|
||||
fmt.Printf("Set %s = %s (in config.yaml)\n", key, value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Database-stored config requires direct mode
|
||||
if err := ensureDirectMode("config set requires direct database access"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
key := args[0]
|
||||
value := args[1]
|
||||
|
||||
ctx := rootCtx
|
||||
|
||||
|
||||
// Special handling for sync.branch to apply validation
|
||||
if strings.TrimSpace(key) == syncbranch.ConfigKey {
|
||||
if err := syncbranch.Set(ctx, store, value); err != nil {
|
||||
@@ -89,25 +111,46 @@ var configGetCmd = &cobra.Command{
|
||||
Short: "Get a configuration value",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Config operations work in direct mode only
|
||||
key := args[0]
|
||||
|
||||
// Check if this is a yaml-only key (startup settings)
|
||||
// These are read from config.yaml via viper, not SQLite. (GH#536)
|
||||
if config.IsYamlOnlyKey(key) {
|
||||
value := config.GetYamlConfig(key)
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(map[string]interface{}{
|
||||
"key": key,
|
||||
"value": value,
|
||||
"location": "config.yaml",
|
||||
})
|
||||
} else {
|
||||
if value == "" {
|
||||
fmt.Printf("%s (not set in config.yaml)\n", key)
|
||||
} else {
|
||||
fmt.Printf("%s\n", value)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Database-stored config requires direct mode
|
||||
if err := ensureDirectMode("config get requires direct database access"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
key := args[0]
|
||||
|
||||
ctx := rootCtx
|
||||
var value string
|
||||
var err error
|
||||
|
||||
|
||||
// Special handling for sync.branch to support env var override
|
||||
if strings.TrimSpace(key) == syncbranch.ConfigKey {
|
||||
value, err = syncbranch.Get(ctx, store)
|
||||
} else {
|
||||
value, err = store.GetConfig(ctx, key)
|
||||
}
|
||||
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting config: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user