返回 DeepSeek-Reasonix
render_remote.go
根目录 / internal / config / render_remote.go
1 package config
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8 func renderRemoteConfig(b *strings.Builder, c *Config, scope RenderScope) {
9 if scope == RenderScopeProject || (!c.Remote.ImportSSHConfig && len(c.Remote.Hosts) == 0 && len(c.Remote.Projects) == 0) {
10 return
11 }
12 b.WriteString("[remote] # SSH remote hosts; user/global only, ./reasonix.toml cannot override\n")
13 if c.Remote.ImportSSHConfig {
14 b.WriteString("import_ssh_config = true # surface ~/.ssh/config aliases in `reasonix remote import`\n")
15 }
16 for _, host := range c.Remote.Hosts {
17 renderRemoteHost(b, host)
18 }
19 for _, project := range c.Remote.Projects {
20 b.WriteString("\n[[remote.projects]]\n")
21 fmt.Fprintf(b, "host_id = %q # referenced [[remote.hosts]] name\n", project.HostID)
22 fmt.Fprintf(b, "workspace = %q\n", project.Workspace)
23 if project.Title != "" {
24 fmt.Fprintf(b, "title = %q\n", project.Title)
25 }
26 if project.SessionOrganization != "" {
27 fmt.Fprintf(b, "session_organization = %q\n", project.SessionOrganization)
28 }
29 }
30 b.WriteString("\n")
31 }
32
33 func renderRemoteHost(b *strings.Builder, host RemoteHostEntry) {
34 b.WriteString("\n[[remote.hosts]]\n")
35 fmt.Fprintf(b, "name = %q\n", host.Name)
36 fmt.Fprintf(b, "host = %q\n", host.Host)
37 if host.Port > 0 {
38 fmt.Fprintf(b, "port = %d\n", host.Port)
39 }
40 if host.User != "" {
41 fmt.Fprintf(b, "user = %q\n", host.User)
42 }
43 if host.IdentityFile != "" {
44 fmt.Fprintf(b, "identity_file = %q # key file path; Reasonix never stores key material\n", host.IdentityFile)
45 }
46 if host.PassphraseEnv != "" {
47 fmt.Fprintf(b, "passphrase_env = %q # env var name; value lives in Reasonix's global .env\n", host.PassphraseEnv)
48 }
49 if host.PasswordEnv != "" {
50 fmt.Fprintf(b, "password_env = %q # env var name; value lives in Reasonix's global .env\n", host.PasswordEnv)
51 }
52 if host.ProxyJump != "" {
53 fmt.Fprintf(b, "proxy_jump = %q # OpenSSH ProxyJump chain\n", host.ProxyJump)
54 }
55 if host.Workspace != "" {
56 fmt.Fprintf(b, "workspace = %q # default remote workspace dir\n", host.Workspace)
57 }
58 if host.ServeInstall != "" {
59 fmt.Fprintf(b, "serve_install = %q # auto|npm|upload|never\n", host.ServeInstall)
60 }
61 if host.CredentialMode != "" {
62 fmt.Fprintf(b, "credential_mode = %q # remote (key on the host) | local-proxy (desktop holds the key; calls tunnel back)\n", host.CredentialMode)
63 }
64 if host.UseSSHConfig {
65 b.WriteString("use_ssh_config = true # layer ~/.ssh/config values under unset fields\n")
66 }
67 for _, forward := range host.Forwards {
68 b.WriteString("\n[[remote.hosts.forwards]]\n")
69 fmt.Fprintf(b, "type = %q # local (-L) | remote (-R)\n", forward.Type)
70 fmt.Fprintf(b, "bind = %q\n", forward.Bind)
71 fmt.Fprintf(b, "target = %q\n", forward.Target)
72 }
73 }
74
74 lines GO