diff options
Diffstat (limited to 'cmd/ask/main.go')
| -rw-r--r-- | cmd/ask/main.go | 39 |
1 files changed, 6 insertions, 33 deletions
diff --git a/cmd/ask/main.go b/cmd/ask/main.go index 73d3e04..72b67e3 100644 --- a/cmd/ask/main.go +++ b/cmd/ask/main.go @@ -2,45 +2,18 @@ package main import ( "context" - "fmt" - "io" "os" - "codeberg.org/snonux/hexai/internal/taskproxy" + "codeberg.org/snonux/hexai/internal/askcli" ) -type taskRunner func(context.Context, []string, io.Reader, io.Writer, io.Writer) (int, error) - -type askRunner struct { - runTask taskRunner -} - -func newAskRunner() askRunner { - return askRunner{runTask: runAskTask} -} - func main() { - if exitCode := newAskRunner().run(os.Args[1:], os.Stdin, os.Stdout, os.Stderr); exitCode != 0 { - os.Exit(exitCode) - } -} - -func (r askRunner) run(args []string, stdin io.Reader, stdout, stderr io.Writer) int { - runner := normalizeAskRunner(r) - exitCode, err := runner.runTask(context.Background(), args, stdin, stdout, stderr) + d := askcli.NewDispatcher(nil) + code, err := d.Dispatch(context.Background(), os.Args[1:], os.Stdin, os.Stdout, os.Stderr) if err != nil { - fmt.Fprintln(stderr, err) + os.Exit(code) } - return exitCode -} - -func normalizeAskRunner(r askRunner) askRunner { - if r.runTask == nil { - r.runTask = runAskTask + if code != 0 { + os.Exit(code) } - return r -} - -func runAskTask(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { - return taskproxy.NewRunner("ask").Run(ctx, args, stdin, stdout, stderr) } |
