|
1 | | -package controller |
2 | | - |
3 | | -import ( |
4 | | - "Orca_Master/cli/cmdopt/listopt" |
5 | | - "Orca_Master/cli/cmdopt/sshopt" |
6 | | - "Orca_Master/cli/common" |
7 | | - "Orca_Master/define/colorcode" |
8 | | - "github.com/desertbit/grumble" |
9 | | - "time" |
10 | | -) |
11 | | - |
12 | | -// 选择id对应的主机命令 |
13 | | -var selectCmd = &grumble.Command{ |
14 | | - Name: "select", |
15 | | - Help: "select the host id waiting to be operated", |
16 | | - Usage: "select [-h | --help] <id>", |
17 | | - Args: func(a *grumble.Args) { |
18 | | - a.Int("id", "set host id") |
19 | | - }, |
20 | | - Run: func(c *grumble.Context) error { |
21 | | - SelectId = c.Args.Int("id") |
22 | | - // 发送命令获取HostList |
23 | | - common.SendSuccessMsg("Server", common.ClientId, "listHosts", "") |
24 | | - // 从管道中接收消息 |
25 | | - select { |
26 | | - case msg := <-common.DefaultMsgChan: |
27 | | - HostLists = listopt.GetHostLists(msg) |
28 | | - case <-time.After(10 * time.Second): |
29 | | - colorcode.PrintMessage(colorcode.SIGN_FAIL, "request timed out") |
30 | | - return nil |
31 | | - } |
32 | | - // 判断设置id是否合法 |
33 | | - if SelectId > len(HostLists) { |
34 | | - SelectId = -1 |
35 | | - colorcode.PrintMessage(colorcode.SIGN_ERROR, "there is no corresponding host in the list") |
36 | | - return nil |
37 | | - } |
38 | | - // 更改终端提示符 |
39 | | - host := HostLists[SelectId-1] |
40 | | - SelectClientId = host.ClientId |
41 | | - SelectIp = host.Ip |
42 | | - SelectVer = host.Version |
43 | | - sshopt.MySsh.Node = SelectClientId |
44 | | - if SelectId <= 0 { |
45 | | - sshopt.MySsh.Node = "Server" |
46 | | - } |
47 | | - App.SetPrompt("Orca[" + Uname + "] → " + SelectIp + " » ") |
48 | | - RemoveCommand() |
49 | | - AddCommand() |
50 | | - sshopt.InitSshOption() |
51 | | - return nil |
52 | | - }, |
53 | | -} |
| 1 | +package controller |
| 2 | + |
| 3 | +import ( |
| 4 | + "Orca_Master/cli/cmdopt/listopt" |
| 5 | + "Orca_Master/cli/cmdopt/sshopt" |
| 6 | + "Orca_Master/cli/common" |
| 7 | + "Orca_Master/define/colorcode" |
| 8 | + "github.com/desertbit/grumble" |
| 9 | + "time" |
| 10 | +) |
| 11 | + |
| 12 | +// 选择id对应的主机命令 |
| 13 | +var selectCmd = &grumble.Command{ |
| 14 | + Name: "select", |
| 15 | + Help: "select the host id waiting to be operated", |
| 16 | + Usage: "select [-h | --help] <id>", |
| 17 | + Args: func(a *grumble.Args) { |
| 18 | + a.Int("id", "set host id") |
| 19 | + }, |
| 20 | + Run: func(c *grumble.Context) error { |
| 21 | + SelectId = c.Args.Int("id") |
| 22 | + // 发送命令获取HostList |
| 23 | + common.SendSuccessMsg("Server", common.ClientId, "listHosts", "") |
| 24 | + // 从管道中接收消息 |
| 25 | + select { |
| 26 | + case msg := <-common.DefaultMsgChan: |
| 27 | + HostLists = listopt.GetHostLists(msg) |
| 28 | + case <-time.After(10 * time.Second): |
| 29 | + colorcode.PrintMessage(colorcode.SIGN_FAIL, "request timed out") |
| 30 | + return nil |
| 31 | + } |
| 32 | + // 判断设置id是否合法 |
| 33 | + if SelectId > len(HostLists) { |
| 34 | + SelectId = -1 |
| 35 | + colorcode.PrintMessage(colorcode.SIGN_ERROR, "there is no corresponding host in the list") |
| 36 | + return nil |
| 37 | + } |
| 38 | + // 更改终端提示符 |
| 39 | + host := HostLists[SelectId-1] |
| 40 | + SelectClientId = host.ClientId |
| 41 | + SelectIp = host.Ip |
| 42 | + SelectVer = host.Version |
| 43 | + sshopt.MySsh.Node = SelectClientId |
| 44 | + if SelectId <= 0 { |
| 45 | + sshopt.MySsh.Node = "Server" |
| 46 | + } |
| 47 | + App.SetPrompt("Orca[" + Uname + "] → " + SelectIp + " » ") |
| 48 | + RemoveCommand() |
| 49 | + AddCommand() |
| 50 | + return nil |
| 51 | + }, |
| 52 | +} |
0 commit comments