-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patharguments_parser.go
More file actions
44 lines (38 loc) · 789 Bytes
/
Copy patharguments_parser.go
File metadata and controls
44 lines (38 loc) · 789 Bytes
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
package main
import (
"strings"
)
func splitHostname(str string) (user string, hostname string) {
if arr := strings.Split(str, "@"); len(arr) > 1 {
return arr[0], arr[1]
} else {
return "", str
}
}
func joinHostname(user string, hostname string) string {
if user != "" {
return user + "@" + hostname
} else {
return hostname
}
}
// Go though arguments, and find one with host
func getTargetHostname(args []string) (user string, hostname string, arg_idx int) {
for idx, arg := range args {
if !strings.HasPrefix(arg, "-") {
if idx == 0 {
hostname = arg
arg_idx = idx
break
} else {
if !strings.HasPrefix(args[idx-1], "-") {
hostname = arg
arg_idx = idx
break
}
}
}
}
user, hostname = splitHostname(hostname)
return
}