From 6103208e0fd382fb5f8c3e317fa28d888d42cb2b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 28 Sep 2025 20:04:52 +0300 Subject: Document config defaults in CLI help --- cmd/hexai-lsp/main.go | 13 ++++++++++++- cmd/hexai-tmux-action/main.go | 12 +++++++++++- cmd/hexai/main.go | 11 ++++++++++- internal/appconfig/config.go | 5 +++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cmd/hexai-lsp/main.go b/cmd/hexai-lsp/main.go index 9764f0b..3704cbf 100644 --- a/cmd/hexai-lsp/main.go +++ b/cmd/hexai-lsp/main.go @@ -3,17 +3,20 @@ package main import ( "flag" + "fmt" "log" "os" "strings" "codeberg.org/snonux/hexai/internal" + "codeberg.org/snonux/hexai/internal/appconfig" "codeberg.org/snonux/hexai/internal/hexailsp" ) func main() { logPath := flag.String("log", "/tmp/hexai-lsp.log", "path to log file (optional)") - configPath := flag.String("config", "", "path to config file") + defaultCfg := defaultConfigPath() + configPath := flag.String("config", "", fmt.Sprintf("path to config file (default: %s)", defaultCfg)) showVersion := flag.Bool("version", false, "print version and exit") flag.Parse() if *showVersion { @@ -26,3 +29,11 @@ func main() { log.Fatalf("server error: %v", err) } } + +func defaultConfigPath() string { + path, err := appconfig.ConfigPath() + if err != nil { + return "$XDG_CONFIG_HOME/hexai/config.toml" + } + return path +} diff --git a/cmd/hexai-tmux-action/main.go b/cmd/hexai-tmux-action/main.go index 3b066cc..32dd725 100644 --- a/cmd/hexai-tmux-action/main.go +++ b/cmd/hexai-tmux-action/main.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "codeberg.org/snonux/hexai/internal/appconfig" "codeberg.org/snonux/hexai/internal/hexaiaction" ) @@ -14,7 +15,8 @@ func main() { infile := flag.String("infile", "", "Read input from this file instead of stdin") outfile := flag.String("outfile", "", "Write output to this file instead of stdout") uiChild := flag.Bool("ui-child", false, "INTERNAL: run interactive UI and write to -outfile atomically") - configPath := flag.String("config", "", "path to config file") + defaultPath := defaultConfigPath() + configPath := flag.String("config", "", fmt.Sprintf("path to config file (default: %s)", defaultPath)) tmuxTarget := flag.String("tmux-target", "", "tmux split target (advanced)") tmuxSplit := flag.String("tmux-split", "v", "tmux split orientation: v or h") tmuxPercent := flag.Int("tmux-percent", 33, "tmux split size percentage (1-100)") @@ -33,3 +35,11 @@ func main() { os.Exit(1) } } + +func defaultConfigPath() string { + path, err := appconfig.ConfigPath() + if err != nil { + return "$XDG_CONFIG_HOME/hexai/config.toml" + } + return path +} diff --git a/cmd/hexai/main.go b/cmd/hexai/main.go index 33b0365..7caedc6 100644 --- a/cmd/hexai/main.go +++ b/cmd/hexai/main.go @@ -25,7 +25,8 @@ func main() { cliEntries = []appconfig.SurfaceConfig{{Provider: cfg.Provider}} } fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) - configFlag := fs.String("config", configPath, "path to config file") + defaultPath := defaultConfigPath() + configFlag := fs.String("config", configPath, fmt.Sprintf("path to config file (default: %s)", defaultPath)) showVersion := fs.Bool("version", false, "print version and exit") selectedFlags := make([]bool, len(cliEntries)) for i, entry := range cliEntries { @@ -105,3 +106,11 @@ func pickDefaultModel(cfg appconfig.App, provider string) string { return strings.TrimSpace(cfg.OpenAIModel) } } + +func defaultConfigPath() string { + cfgPath, err := appconfig.ConfigPath() + if err != nil { + return "$XDG_CONFIG_HOME/hexai/config.toml" + } + return cfgPath +} diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go index 1b134ee..96ac300 100644 --- a/internal/appconfig/config.go +++ b/internal/appconfig/config.go @@ -1046,6 +1046,11 @@ func (a *App) mergeProviderFields(other *App) { } func getConfigPath() (string, error) { + return ConfigPath() +} + +// ConfigPath returns the default config file path ($XDG_CONFIG_HOME/hexai/config.toml or ~/.config/hexai/config.toml). +func ConfigPath() (string, error) { var configPath string if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" { configPath = filepath.Join(xdgConfigHome, "hexai", "config.toml") -- cgit v1.2.3