Example #1
0
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:  "",
			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",
		},
	}
	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.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)
}
Example #2
0
func main() {
	cmd := cli.NewApp()
	cmd.Version = "0.0.10"
	cmd.Name = "gotty"
	cmd.Usage = "Share your terminal as a web application"
	cmd.HideHelp = true

	flags := []flag{
		flag{"address", "a", "IP address to listen"},
		flag{"port", "p", "Port number to listen"},
		flag{"permit-write", "w", "Permit clients to write to the TTY (BE CAREFUL)"},
		flag{"credential", "c", "Credential for Basic Authentication (ex: user:pass, default disabled)"},
		flag{"random-url", "r", "Add a random string to the URL"},
		flag{"random-url-length", "", "Random URL length"},
		flag{"tls", "t", "Enable TLS/SSL"},
		flag{"tls-crt", "", "TLS/SSL crt file path"},
		flag{"tls-key", "", "TLS/SSL key file path"},
		flag{"index", "", "Custom index.html file"},
		flag{"title-format", "", "Title format of browser window"},
		flag{"reconnect", "", "Enable reconnection"},
		flag{"reconnect-time", "", "Time to reconnect"},
		flag{"once", "", "Accept only one client and exit on disconnection"},
		flag{"permit-arguments", "", "Allow to send arguments"},
	}

	mappingHint := map[string]string{
		"index":      "IndexFile",
		"tls":        "EnableTLS",
		"tls-crt":    "TLSCrtFile",
		"tls-key":    "TLSKeyFile",
		"random-url": "EnableRandomUrl",
		"reconnect":  "EnableReconnect",
	}

	cliFlags, err := generateFlags(flags, mappingHint)
	if err != nil {
		exit(err, 3)
	}

	cmd.Flags = append(
		cliFlags,
		cli.StringFlag{
			Name:   "config",
			Value:  "~/.gotty",
			Usage:  "Config file path",
			EnvVar: "GOTTY_CONFIG",
		},
	)

	cmd.Action = func(c *cli.Context) {
		if len(c.Args()) == 0 {
			fmt.Println("Error: No command given.\n")
			cli.ShowAppHelp(c)
			exit(err, 1)
		}

		options := app.DefaultOptions

		configFile := c.String("config")
		_, err := os.Stat(app.ExpandHomeDir(configFile))
		if configFile != "~/.gotty" || !os.IsNotExist(err) {
			if err := app.ApplyConfigFile(&options, configFile); err != nil {
				exit(err, 2)
			}
		}

		applyFlags(&options, flags, mappingHint, c)

		if c.IsSet("credential") {
			options.EnableBasicAuth = true
		}

		app, err := app.New(c.Args(), &options)
		if err != nil {
			exit(err, 3)
		}

		registerSignals(app)

		err = app.Run()
		if err != nil {
			exit(err, 4)
		}
	}

	cli.AppHelpTemplate = helpTemplate

	cmd.Run(os.Args)
}
Example #3
0
File: main.go Project: jay2u/gotty
func main() {
	cmd := cli.NewApp()
	cmd.Version = "0.0.3"
	cmd.Name = "gotty"
	cmd.Usage = "Share your terminal as a web application"
	cmd.HideHelp = true
	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",
		},
		cli.BoolFlag{
			Name:   "random-url, r",
			Usage:  "Add a random string to the URL",
			EnvVar: "GOTTY_RANDOM_URL",
		},
		cli.StringFlag{
			Name:   "profile-file, f",
			Value:  app.DefaultProfileFilePath,
			Usage:  "Path to profile file",
			EnvVar: "GOTTY_PROFILE_FILE",
		},
		cli.BoolFlag{
			Name:   "enable-tls, t",
			Usage:  "Enable TLS/SSL",
			EnvVar: "GOTTY_ENABLE_TLS",
		},
		cli.StringFlag{
			Name:   "tls-cert",
			Value:  app.DefaultTLSCertPath,
			Usage:  "TLS/SSL cert",
			EnvVar: "GOTTY_TLS_CERT",
		},
		cli.StringFlag{
			Name:   "tls-key",
			Value:  app.DefaultTLSKeyPath,
			Usage:  "TLS/SSL key",
			EnvVar: "GOTTY_TLS_KEY",
		},
		cli.StringFlag{
			Name:   "title-format",
			Value:  "GoTTY - {{ .Command }} ({{ .Hostname }})",
			Usage:  "Title format of browser window",
			EnvVar: "GOTTY_TITLE_FORMAT",
		},
		cli.IntFlag{
			Name:   "auto-reconnect",
			Value:  -1,
			Usage:  "Seconds to automatically reconnect to the server when the connection is closed (default: disabled)",
			EnvVar: "GOTTY_AUTO_RECONNECT",
		},
	}
	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, err := app.New(
			app.Options{
				c.String("addr"),
				c.String("port"),
				c.Bool("permit-write"),
				c.String("credential"),
				c.Bool("random-url"),
				c.String("profile-file"),
				c.Bool("enable-tls"),
				c.String("tls-cert"),
				c.String("tls-key"),
				c.String("title-format"),
				c.Int("auto-reconnect"),
				c.Args(),
			},
		)
		if err != nil {
			fmt.Println(err)
			os.Exit(2)
		}

		err = app.Run()
		if err != nil {
			fmt.Println(err)
			os.Exit(3)
		}
	}

	cli.AppHelpTemplate = helpTemplate

	cmd.Run(os.Args)
}
Example #4
0
File: main.go Project: kwketh/gotty
func main() {
	cmd := cli.NewApp()
	cmd.Version = "0.0.2"
	cmd.Name = "gotty"
	cmd.Usage = "Share your terminal as a web application"
	cmd.HideHelp = true
	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",
		},
		cli.BoolFlag{
			Name:   "random-url, r",
			Usage:  "Add a random string to the URL",
			EnvVar: "GOTTY_RANDOM_URL",
		},
	}
	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(
			app.Options{
				c.String("addr"),
				c.String("port"),
				c.Bool("permit-write"),
				c.String("credential"),
				c.Bool("random-url"),
				c.Args(),
			},
		)
		err := app.Run()
		if err != nil {
			fmt.Println(err)
			os.Exit(2)
		}
	}

	cli.AppHelpTemplate = helpTemplate

	cmd.Run(os.Args)
}