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 /internal/hexaicli/run.go | |
| parent | 0ac2d186e84f77d73d924e2c0ce975a17c3a8078 (diff) | |
Add --config flag support across CLI, LSP, and tmux tools
Diffstat (limited to 'internal/hexaicli/run.go')
| -rw-r--r-- | internal/hexaicli/run.go | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/internal/hexaicli/run.go b/internal/hexaicli/run.go index b7745c8..e2aa9a2 100644 --- a/internal/hexaicli/run.go +++ b/internal/hexaicli/run.go @@ -52,7 +52,10 @@ type columnWriter struct { index int } -type selectionContextKey struct{} +type ( + selectionContextKey struct{} + configPathContextKey struct{} +) func buildCLIJobs(cfg appconfig.App) ([]cliJob, error) { entries := cfg.CLIConfigs @@ -160,7 +163,8 @@ func defaultModelForProvider(cfg appconfig.App, provider string) string { func Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) error { // Load configuration with a logger so file-based config is respected. logger := log.New(stderr, "hexai ", log.LstdFlags|log.Lmsgprefix) - cfg := appconfig.Load(logger) + configPath := configPathFromContext(ctx) + cfg := appconfig.LoadWithOptions(logger, appconfig.LoadOptions{ConfigPath: configPath}) if cfg.StatsWindowMinutes > 0 { stats.SetWindow(time.Duration(cfg.StatsWindowMinutes) * time.Minute) } @@ -494,6 +498,24 @@ func WithCLISelection(ctx context.Context, indices []int) context.Context { return context.WithValue(ctx, selectionContextKey{}, cpy) } +// WithCLIConfigPath returns a context that carries the config file path override. +func WithCLIConfigPath(ctx context.Context, path string) context.Context { + if ctx == nil { + ctx = context.Background() + } + return context.WithValue(ctx, configPathContextKey{}, strings.TrimSpace(path)) +} + +func configPathFromContext(ctx context.Context) string { + if ctx == nil { + return "" + } + if v, ok := ctx.Value(configPathContextKey{}).(string); ok { + return strings.TrimSpace(v) + } + return "" +} + func selectionFromContext(ctx context.Context) []int { if ctx == nil { return nil |
