diff options
Diffstat (limited to 'cmd/hexai-tmux-action/main.go')
| -rw-r--r-- | cmd/hexai-tmux-action/main.go | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/cmd/hexai-tmux-action/main.go b/cmd/hexai-tmux-action/main.go index 6249de3..715c41f 100644 --- a/cmd/hexai-tmux-action/main.go +++ b/cmd/hexai-tmux-action/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "io" "os" "strings" @@ -11,6 +12,10 @@ import ( "codeberg.org/snonux/hexai/internal/hexaiaction" ) +// runCommand is the seam for testing: override in tests to avoid launching +// the real tmux action. +var runCommand = hexaiaction.RunCommand + 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") @@ -22,16 +27,38 @@ func main() { tmuxPercent := flag.Int("tmux-percent", 33, "tmux split size percentage (1-100)") flag.Parse() - opts := hexaiaction.Options{ - Infile: *infile, Outfile: *outfile, - UIChild: *uiChild, TmuxTarget: *tmuxTarget, TmuxSplit: *tmuxSplit, TmuxPercent: *tmuxPercent, - } - ctx := context.Background() - if path := strings.TrimSpace(*configPath); path != "" { - ctx = hexaiaction.WithConfigPath(ctx, path) + opts := actionOptions{ + infile: *infile, outfile: *outfile, + uiChild: *uiChild, configPath: *configPath, + tmuxTarget: *tmuxTarget, tmuxSplit: *tmuxSplit, tmuxPercent: *tmuxPercent, } - if err := hexaiaction.RunCommand(ctx, opts, os.Stdin, os.Stdout, os.Stderr); err != nil { + if err := run(opts, os.Stdin, os.Stdout, os.Stderr); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } + +// actionOptions holds the parsed command-line flags for hexai-tmux-action. +type actionOptions struct { + infile string + outfile string + uiChild bool + configPath string + tmuxTarget string + tmuxSplit string + tmuxPercent int +} + +// run builds the hexaiaction.Options and context, then delegates to runCommand. +func run(opts actionOptions, stdin io.Reader, stdout, stderr io.Writer) error { + haOpts := hexaiaction.Options{ + Infile: opts.infile, Outfile: opts.outfile, + UIChild: opts.uiChild, TmuxTarget: opts.tmuxTarget, + TmuxSplit: opts.tmuxSplit, TmuxPercent: opts.tmuxPercent, + } + ctx := context.Background() + if path := strings.TrimSpace(opts.configPath); path != "" { + ctx = hexaiaction.WithConfigPath(ctx, path) + } + return runCommand(ctx, haOpts, stdin, stdout, stderr) +} |
