跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

run_p.go

43 行 · 1.2 KB历史下载
1package main
2
3import (
4 "fmt"
5 "strconv"
6 "strings"
7)
8
9// parseFlagP parses -p flag, akin to `docker run -p` flags.
10// The returned value conforms to the `ssh -L` syntax
11func parseFlagP(s string) (string, error) {
12 split := strings.Split(s, ":")
13 switch len(split) {
14 case 1:
15 port, err := strconv.Atoi(split[0])
16 if err != nil {
17 return "", fmt.Errorf("invalid port %q", split[0])
18 }
19 return fmt.Sprintf("0.0.0.0:%d:localhost:%d", port, port), nil
20 case 2:
21 localPort, err := strconv.Atoi(split[0])
22 if err != nil {
23 return "", fmt.Errorf("invalid port %q", split[0])
24 }
25 remotePort, err := strconv.Atoi(split[1])
26 if err != nil {
27 return "", fmt.Errorf("invalid port %q", split[1])
28 }
29 return fmt.Sprintf("0.0.0.0:%d:localhost:%d", localPort, remotePort), nil
30 case 3:
31 localIP := split[0]
32 localPort, err := strconv.Atoi(split[1])
33 if err != nil {
34 return "", fmt.Errorf("invalid port %q", split[1])
35 }
36 remotePort, err := strconv.Atoi(split[2])
37 if err != nil {
38 return "", fmt.Errorf("invalid port %q", split[2])
39 }
40 return fmt.Sprintf("%s:%d:localhost:%d", localIP, localPort, remotePort), nil
41 }
42 return "", fmt.Errorf("cannot parse %q, should be [[LOCALIP:]LOCALPORT:]REMOTEPORT", s)
43}