generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
68 lines (61 loc) · 1.6 KB
/
main.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
package main
import (
"fmt"
"os"
"syscall"
)
//go:generate go run scripts/generate-usage.go
//go:generate go run scripts/generate-license.go
func usage(error string, exit bool, exitCode int, exitFunc func(code int)) {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
if error != "" {
_, _ = os.Stderr.Write([]byte("\033[31mError: " + error + "\033[0m\n"))
}
_, _ = os.Stdout.Write([]byte("\n"))
_, _ = os.Stdout.Write([]byte(usageTextColored))
} else {
if error != "" {
_, _ = os.Stderr.Write([]byte("Error: " + error + "\n"))
}
_, _ = os.Stdout.Write([]byte("\n"))
_, _ = os.Stdout.Write([]byte(usageText))
}
if exit {
exitFunc(exitCode)
}
}
func license(argv []string) {
if len(argv) > 0 {
usage("license takes no arguments", true, 1, os.Exit)
}
_, _ = os.Stdout.Write([]byte(licenseText))
}
func main() {
args := os.Args
if len(args) < 2 {
usage("not enough parameters", true, 1, os.Exit)
}
switch args[1] {
case "-h":
fallthrough
case "--help":
usage("", false, 0, os.Exit)
os.Exit(0)
case "console":
console(os.Stdin, os.Stdout, os.Stderr, args[2:], syscall.Exec, os.Exit)
case "signal":
signal(os.Stderr, args[2:], syscall.Exit, func(pid int) (Process, error) {
return os.FindProcess(pid)
})
case "wait-signal":
waitSignal(os.Stdout, args[2:], os.Exit)
case "write-file":
writeFile(args[2:], os.Stdin, os.Stderr, os.Exit)
case "forward-server":
forwardServer(os.Stdin, os.Stdout, os.Stderr, os.Exit)
case "license":
license(args[2:])
default:
usage(fmt.Sprintf("invalid mode: %s", args[1]), true, 1, os.Exit)
}
}