forked from yudai/gotty
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
75 lines (65 loc) · 1.47 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
69
70
71
72
73
74
75
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/yudai/gotty/app"
)
func main() {
cmd := cli.NewApp()
cmd.Version = "0.0.2"
cmd.Name = "gotty"
cmd.Usage = "Share your terminal as a web application"
cmd.Flags = []cli.Flag{
cli.StringFlag{
Name: "addr, a",
Value: "",
Usage: "IP address to listen",
EnvVar: "GOTTY_ADDR",
},
cli.StringFlag{
Name: "port, p",
Value: "8080",
Usage: "Port number to listen",
EnvVar: "GOTTY_PORT",
},
cli.BoolFlag{
Name: "permit-write, w",
Usage: "Permit clients to write to the TTY (BE CAREFUL)",
EnvVar: "GOTTY_PERMIT_WRITE",
},
cli.StringFlag{
Name: "credential, c",
Usage: "Credential for Basic Authentication (ex: user:pass)",
EnvVar: "GOTTY_CREDENTIAL",
},
}
cmd.Action = func(c *cli.Context) {
if len(c.Args()) == 0 {
fmt.Println("Error: No command given.\n")
cli.ShowAppHelp(c)
os.Exit(1)
}
app := app.New(c.String("addr"), c.String("port"), c.Bool("permit-write"), c.String("credential"), c.Args())
err := app.Run()
if err != nil {
fmt.Println(err)
os.Exit(2)
}
}
cmd.HideHelp = true
cli.AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.Name}} [options] <command> [<arguments...>]
VERSION:
{{.Version}}{{if or .Author .Email}}
AUTHOR:{{if .Author}}
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
{{.Email}}{{end}}{{end}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}
`
cmd.Run(os.Args)
}