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()
|
2015-08-22 14:41:03 +08:00
|
|
|
cmd.Version = "0.0.3"
|
2015-08-16 17:47:23 +08:00
|
|
|
cmd.Name = "gotty"
|
|
|
|
cmd.Usage = "Share your terminal as a web application"
|
2015-08-21 17:42:04 +08:00
|
|
|
cmd.HideHelp = true
|
2015-08-16 17:47:23 +08:00
|
|
|
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",
|
|
|
|
},
|
2015-08-20 14:40:38 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "credential, c",
|
|
|
|
Usage: "Credential for Basic Authentication (ex: user:pass)",
|
|
|
|
EnvVar: "GOTTY_CREDENTIAL",
|
|
|
|
},
|
2015-08-19 19:35:04 +08:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "random-url, r",
|
|
|
|
Usage: "Add a random string to the URL",
|
|
|
|
EnvVar: "GOTTY_RANDOM_URL",
|
|
|
|
},
|
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)
|
|
|
|
}
|
2015-08-21 11:48:07 +08:00
|
|
|
app := app.New(
|
|
|
|
app.Options{
|
|
|
|
c.String("addr"),
|
|
|
|
c.String("port"),
|
|
|
|
c.Bool("permit-write"),
|
|
|
|
c.String("credential"),
|
|
|
|
c.Bool("random-url"),
|
|
|
|
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
|
|
|
|
2015-08-21 17:42:04 +08:00
|
|
|
cli.AppHelpTemplate = helpTemplate
|
2015-08-17 10:30:44 +08:00
|
|
|
|
2015-08-16 17:47:23 +08:00
|
|
|
cmd.Run(os.Args)
|
|
|
|
}
|