parent
65f9eac352
commit
edff8721cf
|
@ -31,6 +31,7 @@ var (
|
||||||
flagAppName string
|
flagAppName string
|
||||||
flagAddr string
|
flagAddr string
|
||||||
flagShell string
|
flagShell string
|
||||||
|
flagDir string
|
||||||
flagLogLevel int
|
flagLogLevel int
|
||||||
flagDev bool
|
flagDev bool
|
||||||
flagVer bool
|
flagVer bool
|
||||||
|
@ -42,6 +43,7 @@ func init() {
|
||||||
flag.StringVar(&flagAppName, "name", "gterm", "the application title")
|
flag.StringVar(&flagAppName, "name", "gterm", "the application title")
|
||||||
flag.StringVar(&flagAddr, "addr", ":8000", "address to bind")
|
flag.StringVar(&flagAddr, "addr", ":8000", "address to bind")
|
||||||
flag.StringVar(&flagShell, "shell", "bash", "the shell behind")
|
flag.StringVar(&flagShell, "shell", "bash", "the shell behind")
|
||||||
|
flag.StringVar(&flagDir, "dir", ".", "the working dir")
|
||||||
flag.Var(&flagArgs, "arg", "additional args to pass to cmd")
|
flag.Var(&flagArgs, "arg", "additional args to pass to cmd")
|
||||||
flag.BoolVar(&flagDev, "dev", false, "is development mode")
|
flag.BoolVar(&flagDev, "dev", false, "is development mode")
|
||||||
flag.IntVar(&flagLogLevel, "log-level", 9, "log level")
|
flag.IntVar(&flagLogLevel, "log-level", 9, "log level")
|
||||||
|
@ -73,6 +75,7 @@ func main() {
|
||||||
g.AppName = flagAppName
|
g.AppName = flagAppName
|
||||||
g.Cmd = flagShell
|
g.Cmd = flagShell
|
||||||
g.Args = flagArgs
|
g.Args = flagArgs
|
||||||
|
g.Dir = flagDir
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: flagAddr,
|
Addr: flagAddr,
|
||||||
|
|
5
gterm.go
5
gterm.go
|
@ -42,6 +42,8 @@ type GTerm struct {
|
||||||
Args []string
|
Args []string
|
||||||
// Command is the path to the binary we should create a TTY for
|
// Command is the path to the binary we should create a TTY for
|
||||||
Cmd string
|
Cmd string
|
||||||
|
// Dir working dir
|
||||||
|
Dir string
|
||||||
// Envs env pairs to pass to the command
|
// Envs env pairs to pass to the command
|
||||||
Envs []string
|
Envs []string
|
||||||
// ErrorLimit defines the number of consecutive errors that can happen
|
// ErrorLimit defines the number of consecutive errors that can happen
|
||||||
|
@ -145,6 +147,9 @@ func (g *GTerm) WS(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
cmd := exec.Command(g.Cmd, g.Args...)
|
cmd := exec.Command(g.Cmd, g.Args...)
|
||||||
cmd.Env = g.Envs
|
cmd.Env = g.Envs
|
||||||
|
if g.Dir != "" && g.Dir != "." {
|
||||||
|
cmd.Dir = g.Dir
|
||||||
|
}
|
||||||
tty, err := pty.Start(cmd)
|
tty, err := pty.Start(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error(err)
|
l.Error(err)
|
||||||
|
|
Loading…
Reference in New Issue