diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-28 17:30:44 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-28 17:30:44 +0300 |
| commit | 0761409497041c752086b9aded08cf9e32e30fd2 (patch) | |
| tree | e62721bc119d4ae435d2609292faea06a68244a4 /cmd | |
| parent | 0ac2d186e84f77d73d924e2c0ce975a17c3a8078 (diff) | |
Add --config flag support across CLI, LSP, and tmux tools
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/hexai-lsp/main.go | 5 | ||||
| -rw-r--r-- | cmd/hexai-tmux-action/main.go | 8 | ||||
| -rw-r--r-- | cmd/hexai/main.go | 36 |
3 files changed, 45 insertions, 4 deletions
diff --git a/cmd/hexai-lsp/main.go b/cmd/hexai-lsp/main.go index f2cad6d..9764f0b 100644 --- a/cmd/hexai-lsp/main.go +++ b/cmd/hexai-lsp/main.go @@ -5,6 +5,7 @@ import ( "flag" "log" "os" + "strings" "codeberg.org/snonux/hexai/internal" "codeberg.org/snonux/hexai/internal/hexailsp" @@ -12,6 +13,7 @@ import ( func main() { logPath := flag.String("log", "/tmp/hexai-lsp.log", "path to log file (optional)") + configPath := flag.String("config", "", "path to config file") showVersion := flag.Bool("version", false, "print version and exit") flag.Parse() if *showVersion { @@ -19,7 +21,8 @@ func main() { return } - if err := hexailsp.Run(*logPath, os.Stdin, os.Stdout, os.Stderr); err != nil { + path := strings.TrimSpace(*configPath) + if err := hexailsp.RunWithConfig(*logPath, path, os.Stdin, os.Stdout, os.Stderr); err != nil { log.Fatalf("server error: %v", err) } } diff --git a/cmd/hexai-tmux-action/main.go b/cmd/hexai-tmux-action/main.go index 2d8793b..3b066cc 100644 --- a/cmd/hexai-tmux-action/main.go +++ b/cmd/hexai-tmux-action/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "os" + "strings" "codeberg.org/snonux/hexai/internal/hexaiaction" ) @@ -13,6 +14,7 @@ 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") 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)") @@ -22,7 +24,11 @@ func main() { Infile: *infile, Outfile: *outfile, UIChild: *uiChild, TmuxTarget: *tmuxTarget, TmuxSplit: *tmuxSplit, TmuxPercent: *tmuxPercent, } - if err := hexaiaction.RunCommand(context.Background(), opts, os.Stdin, os.Stdout, os.Stderr); err != nil { + ctx := context.Background() + if path := strings.TrimSpace(*configPath); path != "" { + ctx = hexaiaction.WithConfigPath(ctx, path) + } + if err := hexaiaction.RunCommand(ctx, opts, os.Stdin, os.Stdout, os.Stderr); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } diff --git a/cmd/hexai/main.go b/cmd/hexai/main.go index 4c4fbd2..a6fc1a6 100644 --- a/cmd/hexai/main.go +++ b/cmd/hexai/main.go @@ -17,13 +17,15 @@ import ( ) func main() { + configPath, remaining := splitConfigPath(os.Args[1:]) logger := log.New(io.Discard, "", 0) - cfg := appconfig.Load(logger) + cfg := appconfig.LoadWithOptions(logger, appconfig.LoadOptions{ConfigPath: configPath}) cliEntries := cfg.CLIConfigs if len(cliEntries) == 0 { cliEntries = []appconfig.SurfaceConfig{{Provider: cfg.Provider}} } fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) + configFlag := fs.String("config", configPath, "path to config file") showVersion := fs.Bool("version", false, "print version and exit") selectedFlags := make([]bool, len(cliEntries)) for i, entry := range cliEntries { @@ -39,7 +41,7 @@ func main() { desc := fmt.Sprintf("use only provider #%d (%s:%s)", i, provider, model) fs.BoolVar(&selectedFlags[i], name, false, desc) } - _ = fs.Parse(os.Args[1:]) + _ = fs.Parse(remaining) if *showVersion { fmt.Fprintln(os.Stdout, internal.Version) return @@ -54,11 +56,41 @@ func main() { if len(selection) > 0 { ctx = hexaicli.WithCLISelection(ctx, selection) } + if path := strings.TrimSpace(*configFlag); path != "" { + ctx = hexaicli.WithCLIConfigPath(ctx, path) + } if err := hexaicli.Run(ctx, fs.Args(), os.Stdin, os.Stdout, os.Stderr); err != nil { os.Exit(1) } } +func splitConfigPath(args []string) (string, []string) { + var path string + rest := make([]string, 0, len(args)) + skip := false + for i := 0; i < len(args); i++ { + if skip { + skip = false + continue + } + arg := args[i] + switch { + case arg == "--config" || arg == "-config": + if i+1 < len(args) { + path = args[i+1] + skip = true + } + case strings.HasPrefix(arg, "--config="): + path = arg[len("--config="):] + case strings.HasPrefix(arg, "-config="): + path = arg[len("-config="):] + default: + rest = append(rest, arg) + } + } + return strings.TrimSpace(path), rest +} + func pickDefaultModel(cfg appconfig.App, provider string) string { switch strings.ToLower(strings.TrimSpace(provider)) { case "ollama": |
