feat: add dir option
continuous-integration/drone/tag Build is passing Details

master v0.1.4
Evan Chen 2021-11-18 10:49:15 +08:00
parent 65f9eac352
commit edff8721cf
2 changed files with 8 additions and 0 deletions

View File

@ -31,6 +31,7 @@ var (
flagAppName string
flagAddr string
flagShell string
flagDir string
flagLogLevel int
flagDev bool
flagVer bool
@ -42,6 +43,7 @@ func init() {
flag.StringVar(&flagAppName, "name", "gterm", "the application title")
flag.StringVar(&flagAddr, "addr", ":8000", "address to bind")
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.BoolVar(&flagDev, "dev", false, "is development mode")
flag.IntVar(&flagLogLevel, "log-level", 9, "log level")
@ -73,6 +75,7 @@ func main() {
g.AppName = flagAppName
g.Cmd = flagShell
g.Args = flagArgs
g.Dir = flagDir
server := &http.Server{
Addr: flagAddr,

View File

@ -42,6 +42,8 @@ type GTerm struct {
Args []string
// Command is the path to the binary we should create a TTY for
Cmd string
// Dir working dir
Dir string
// Envs env pairs to pass to the command
Envs []string
// 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.Env = g.Envs
if g.Dir != "" && g.Dir != "." {
cmd.Dir = g.Dir
}
tty, err := pty.Start(cmd)
if err != nil {
l.Error(err)