-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxsh-cli.go
87 lines (73 loc) · 1.52 KB
/
xsh-cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
. "github.com/xied5531/xsh/base"
. "github.com/xied5531/xsh/sh"
"strings"
)
func runTask() {
task := SshTask{}
CurEnv.Output = *Output
Out(task.Do())
}
func runCmd() {
if _, ok := XHostMap[*Group]; !ok {
Error.Printf("host group[%s] not found\n", *Group)
return
}
if len(strings.Trim(*Cmd, " ")) == 0 {
Error.Printf("command line[%s] empty\n", *Cmd)
return
}
action := SshAction{
Name: "Default",
Group: *Group,
Steps: []Step{{
Type: "cmd",
Commands: strings.Split(*Cmd, XConfig.CommandSep),
Su: *Su,
}},
}
CurEnv.Output = *Output
Out(action.Do())
}
func runCopy() {
if _, ok := XHostMap[*Group]; !ok {
Error.Printf("host group[%s] not found\n", *Group)
return
}
if *Direction == "" || *Local == "" || *Remote == "" {
Error.Println("direction or local or remote not found")
return
}
action := SshAction{
Name: "Default",
Group: *Group,
Steps: []Step{{
Type: "copy",
Direction: *Direction,
Local: *Local,
Remote: *Remote,
}},
}
CurEnv.Output = *Output
Out(action.Do())
}
func runCrypt() {
XConfig.Crypt.Type = *CryptType
XConfig.Crypt.Key = *CryptKey
if *Plain != "" {
if c, e := GetMaskPassword(*Plain); e != nil {
fmt.Printf("%s -> error: %s\n", *Plain, e.Error())
} else {
fmt.Printf("%s -> %s\n", *Plain, c)
}
}
if *Cipher != "" {
if p, e := GetPlainPassword(*Cipher); e != nil {
fmt.Printf("%s -> error: %s\n", *Cipher, e.Error())
} else {
fmt.Printf("%s -> %s\n", *Cipher, p)
}
}
}