diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-02 11:41:44 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-02 11:41:55 +0300 |
| commit | 266bedf71fe8a54b86af038889522a68bae562a8 (patch) | |
| tree | 6ca2b100e63ea5b4e746e71b2b79b626ba70c597 /internal/hexaicli | |
| parent | d9184a5bfdc39d40232cb0d66a350daffcd7a326 (diff) | |
Drop hexai edit; document hexai config only.v0.38.4
The CLI now opens the config file only via hexai config (and --config).
README, usage, and configuration docs describe the subcommand. Version 0.38.4.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'internal/hexaicli')
| -rw-r--r-- | internal/hexaicli/runner.go | 25 | ||||
| -rw-r--r-- | internal/hexaicli/runner_test.go | 55 |
2 files changed, 80 insertions, 0 deletions
diff --git a/internal/hexaicli/runner.go b/internal/hexaicli/runner.go index f372021..eaae1cd 100644 --- a/internal/hexaicli/runner.go +++ b/internal/hexaicli/runner.go @@ -67,6 +67,31 @@ func NewRunner() *Runner { func (r *Runner) Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) error { runner := normalizeRunner(r) + if len(args) > 0 { + sub := args[0] + if sub == "config" { + if len(args) > 1 { + err := fmt.Errorf(`hexai %s: unexpected arguments (use only %q)`, sub, sub) + _, _ = fmt.Fprintf(stderr, logging.AnsiBase+"%v"+logging.AnsiReset+"\n", err) + return err + } + cfgPath := strings.TrimSpace(configPathFromContext(ctx)) + if cfgPath == "" { + p, pathErr := appconfig.ConfigPath() + if pathErr != nil { + err := fmt.Errorf("hexai %s: %w", sub, pathErr) + _, _ = fmt.Fprintf(stderr, logging.AnsiBase+"%v"+logging.AnsiReset+"\n", err) + return err + } + cfgPath = p + } + if err := editor.OpenFile(cfgPath); err != nil { + _, _ = fmt.Fprintf(stderr, logging.AnsiBase+"hexai %s: %v"+logging.AnsiReset+"\n", sub, err) + return err + } + return nil + } + } if spec, ok, err := tpsSimulationFromContext(ctx); err != nil { _, _ = fmt.Fprintln(stderr, logging.AnsiBase+err.Error()+logging.AnsiReset) return err diff --git a/internal/hexaicli/runner_test.go b/internal/hexaicli/runner_test.go index 1d438b0..009af54 100644 --- a/internal/hexaicli/runner_test.go +++ b/internal/hexaicli/runner_test.go @@ -4,10 +4,12 @@ import ( "bytes" "context" "log" + "path/filepath" "strings" "testing" "codeberg.org/snonux/hexai/internal/appconfig" + "codeberg.org/snonux/hexai/internal/editor" "codeberg.org/snonux/hexai/internal/llm" "codeberg.org/snonux/hexai/internal/stats" ) @@ -59,3 +61,56 @@ func TestRunner_UsesInjectedDependencies(t *testing.T) { t.Fatalf("expected one global status update, got %d", sink.globalCalls) } } + +func TestRunner_ConfigSubcommand_OpensConfigFromContext(t *testing.T) { + old := editor.RunEditor + t.Cleanup(func() { editor.RunEditor = old }) + t.Setenv("EDITOR", "true") + var gotPath string + editor.RunEditor = func(_, path string) error { + gotPath = path + return nil + } + cfgFile := filepath.Join(t.TempDir(), "hexai", "config.toml") + ctx := WithCLIConfigPath(context.Background(), cfgFile) + runner := NewRunner() + if err := runner.Run(ctx, []string{"config"}, strings.NewReader(""), &bytes.Buffer{}, &bytes.Buffer{}); err != nil { + t.Fatalf("Run: %v", err) + } + if gotPath != cfgFile { + t.Fatalf("opened %q, want %q", gotPath, cfgFile) + } +} + +func TestRunner_ConfigSubcommand_UsesXDGWhenNoOverride(t *testing.T) { + old := editor.RunEditor + t.Cleanup(func() { editor.RunEditor = old }) + t.Setenv("HEXAI_EDITOR", "true") + xdg := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", xdg) + var gotPath string + editor.RunEditor = func(_, path string) error { + gotPath = path + return nil + } + runner := NewRunner() + want := filepath.Join(xdg, "hexai", "config.toml") + if err := runner.Run(context.Background(), []string{"config"}, strings.NewReader(""), &bytes.Buffer{}, &bytes.Buffer{}); err != nil { + t.Fatalf("Run: %v", err) + } + if gotPath != want { + t.Fatalf("opened %q, want %q", gotPath, want) + } +} + +func TestRunner_ConfigSubcommand_RejectsExtraArgs(t *testing.T) { + runner := NewRunner() + var stderr bytes.Buffer + err := runner.Run(context.Background(), []string{"config", "nope"}, strings.NewReader(""), &bytes.Buffer{}, &stderr) + if err == nil { + t.Fatal("expected error") + } + if !strings.Contains(err.Error(), "unexpected arguments") { + t.Fatalf("err = %v", err) + } +} |
