2015-08-16 09:47:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
|
|
|
|
"github.com/yudai/gotty/app"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
cmd := cli.NewApp()
|
2015-08-22 06:41:03 +00:00
|
|
|
cmd.Version = "0.0.3"
|
2015-08-16 09:47:23 +00:00
|
|
|
cmd.Name = "gotty"
|
|
|
|
cmd.Usage = "Share your terminal as a web application"
|
2015-08-21 09:42:04 +00:00
|
|
|
cmd.HideHelp = true
|
2015-08-16 09:47:23 +00:00
|
|
|
cmd.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "addr, a",
|
|
|
|
Value: "",
|
2015-08-17 02:30:44 +00:00
|
|
|
Usage: "IP address to listen",
|
2015-08-16 09:47:23 +00:00
|
|
|
EnvVar: "GOTTY_ADDR",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "port, p",
|
|
|
|
Value: "8080",
|
2015-08-17 02:30:44 +00:00
|
|
|
Usage: "Port number to listen",
|
2015-08-16 09:47:23 +00:00
|
|
|
EnvVar: "GOTTY_PORT",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "permit-write, w",
|
2015-08-17 02:30:44 +00:00
|
|
|
Usage: "Permit clients to write to the TTY (BE CAREFUL)",
|
2015-08-16 09:47:23 +00:00
|
|
|
EnvVar: "GOTTY_PERMIT_WRITE",
|
|
|
|
},
|
2015-08-20 06:40:38 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "credential, c",
|
|
|
|
Usage: "Credential for Basic Authentication (ex: user:pass)",
|
|
|
|
EnvVar: "GOTTY_CREDENTIAL",
|
|
|
|
},
|
2015-08-19 11:35:04 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "random-url, r",
|
|
|
|
Usage: "Add a random string to the URL",
|
|
|
|
EnvVar: "GOTTY_RANDOM_URL",
|
|
|
|
},
|
2015-08-23 13:55:06 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "profile-file, f",
|
|
|
|
Value: app.DefaultProfileFilePath,
|
|
|
|
Usage: "Path to profile file",
|
|
|
|
EnvVar: "GOTTY_PROFILE_FILE",
|
|
|
|
},
|
2015-08-23 05:04:31 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "title-format",
|
|
|
|
Value: "GoTTY - {{ .Command }} ({{ .Hostname }})",
|
|
|
|
Usage: "Title format of browser window",
|
2015-08-23 12:32:32 +00:00
|
|
|
EnvVar: "GOTTY_TITLE_FORMAT",
|
2015-08-23 05:04:31 +00:00
|
|
|
},
|
2015-08-16 09:47:23 +00:00
|
|
|
}
|
|
|
|
cmd.Action = func(c *cli.Context) {
|
|
|
|
if len(c.Args()) == 0 {
|
2015-08-17 02:30:44 +00:00
|
|
|
fmt.Println("Error: No command given.\n")
|
2015-08-16 09:47:23 +00:00
|
|
|
cli.ShowAppHelp(c)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-08-23 11:40:18 +00:00
|
|
|
|
|
|
|
app, err := app.New(
|
2015-08-21 03:48:07 +00:00
|
|
|
app.Options{
|
|
|
|
c.String("addr"),
|
|
|
|
c.String("port"),
|
|
|
|
c.Bool("permit-write"),
|
|
|
|
c.String("credential"),
|
|
|
|
c.Bool("random-url"),
|
2015-08-23 13:55:06 +00:00
|
|
|
c.String("profile-file"),
|
2015-08-23 05:04:31 +00:00
|
|
|
c.String("title-format"),
|
2015-08-21 03:48:07 +00:00
|
|
|
c.Args(),
|
|
|
|
},
|
|
|
|
)
|
2015-08-16 09:47:23 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
2015-08-23 11:40:18 +00:00
|
|
|
|
|
|
|
err = app.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(3)
|
|
|
|
}
|
2015-08-16 09:47:23 +00:00
|
|
|
}
|
2015-08-17 02:30:44 +00:00
|
|
|
|
2015-08-21 09:42:04 +00:00
|
|
|
cli.AppHelpTemplate = helpTemplate
|
2015-08-17 02:30:44 +00:00
|
|
|
|
2015-08-16 09:47:23 +00:00
|
|
|
cmd.Run(os.Args)
|
|
|
|
}
|