返回 DeepSeek-Reasonix
main.go
1 // Command reasonix-cli-launcher is the stable Windows console entry point for
2 // versioned desktop installations. It delegates to the active full CLI and
3 // deliberately contains no Reasonix engine code.
4 package main
5
6 import (
7 "errors"
8 "fmt"
9 "io"
10 "os"
11 "os/exec"
12 "path/filepath"
13
14 "reasonix/internal/installlayout"
15 )
16
17 func main() {
18 exe, err := os.Executable()
19 if err != nil {
20 fmt.Fprintln(os.Stderr, "reasonix: locate CLI launcher:", err)
21 os.Exit(1)
22 }
23 os.Exit(runCLI(exe, os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
24 }
25
26 func runCLI(executable string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
27 root := filepath.Dir(filepath.Clean(executable))
28 target, err := installlayout.ActiveCLIPathFor(root, "windows")
29 if err != nil {
30 fmt.Fprintln(stderr, "reasonix: resolve active CLI:", err)
31 return 1
32 }
33 if same, err := installlayout.SameRegularFile(executable, target); err != nil {
34 fmt.Fprintln(stderr, "reasonix: validate active CLI:", err)
35 return 1
36 } else if same {
37 fmt.Fprintln(stderr, "reasonix: active CLI resolves to the launcher itself")
38 return 1
39 }
40 cmd := exec.Command(target, args...)
41 cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, stderr
42 cmd.Env = os.Environ()
43 if err := cmd.Run(); err != nil {
44 var exit *exec.ExitError
45 if errors.As(err, &exit) {
46 return exit.ExitCode()
47 }
48 fmt.Fprintln(stderr, "reasonix: start active CLI:", err)
49 return 1
50 }
51 return 0
52 }
53
53 lines GO