gotty/main.go

76 lines
1.5 KiB
Go
Raw Normal View History

2015-08-16 17:47:23 +08:00
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/yudai/gotty/app"
)
func main() {
cmd := cli.NewApp()
cmd.Version = "0.0.1"
cmd.Name = "gotty"
cmd.Usage = "Share your terminal as a web application"
cmd.Flags = []cli.Flag{
cli.StringFlag{
Name: "addr, a",
Value: "",
2015-08-17 10:30:44 +08:00
Usage: "IP address to listen",
2015-08-16 17:47:23 +08:00
EnvVar: "GOTTY_ADDR",
},
cli.StringFlag{
Name: "port, p",
Value: "8080",
2015-08-17 10:30:44 +08:00
Usage: "Port number to listen",
2015-08-16 17:47:23 +08:00
EnvVar: "GOTTY_PORT",
},
cli.BoolFlag{
Name: "permit-write, w",
2015-08-17 10:30:44 +08:00
Usage: "Permit clients to write to the TTY (BE CAREFUL)",
2015-08-16 17:47:23 +08:00
EnvVar: "GOTTY_PERMIT_WRITE",
},
cli.StringFlag{
Name: "credential, c",
Usage: "Credential for Basic Authentication (ex: user:pass)",
EnvVar: "GOTTY_CREDENTIAL",
},
2015-08-16 17:47:23 +08:00
}
cmd.Action = func(c *cli.Context) {
if len(c.Args()) == 0 {
2015-08-17 10:30:44 +08:00
fmt.Println("Error: No command given.\n")
2015-08-16 17:47:23 +08:00
cli.ShowAppHelp(c)
os.Exit(1)
}
app := app.New(c.String("addr"), c.String("port"), c.Bool("permit-write"), c.String("credential"), c.Args())
2015-08-16 17:47:23 +08:00
err := app.Run()
if err != nil {
fmt.Println(err)
os.Exit(2)
}
}
2015-08-17 10:30:44 +08:00
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}}
`
2015-08-16 17:47:23 +08:00
cmd.Run(os.Args)
}