feat: use pty

This commit is contained in:
fiftin 2024-04-05 13:23:15 +02:00
parent 205fe71bcb
commit 955053dd98
No known key found for this signature in database
GPG Key ID: 044381366A5D4731
3 changed files with 8 additions and 4 deletions

View File

@ -5,9 +5,9 @@ import (
"github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/lib"
"github.com/ansible-semaphore/semaphore/util"
"github.com/creack/pty"
"os"
"os/exec"
"strings"
)
type AnsiblePlaybook struct {
@ -56,11 +56,12 @@ func (p AnsiblePlaybook) runCmd(command string, args []string) error {
func (p AnsiblePlaybook) RunPlaybook(args []string, environmentVars *[]string, cb func(*os.Process)) error {
cmd := p.makeCmd("ansible-playbook", args, environmentVars)
p.Logger.LogCmd(cmd)
cmd.Stdin = strings.NewReader("")
err := cmd.Start()
ptmx, err := pty.Start(cmd)
if err != nil {
return err
panic(err)
}
defer func() { _ = ptmx.Close() }()
cb(cmd.Process)
return cmd.Wait()
}

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.21
require (
github.com/Masterminds/squirrel v1.5.4
github.com/coreos/go-oidc/v3 v3.9.0
github.com/creack/pty v1.1.21
github.com/go-git/go-git/v5 v5.11.0
github.com/go-gorp/gorp/v3 v3.1.0
github.com/go-ldap/ldap/v3 v3.4.6

2
go.sum
View File

@ -22,6 +22,8 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
github.com/coreos/go-oidc/v3 v3.9.0 h1:0J/ogVOd4y8P0f0xUh8l9t07xRP/d8tccvjHl2dcsSo=
github.com/coreos/go-oidc/v3 v3.9.0/go.mod h1:rTKz2PYwftcrtoCzV5g5kvfJoWcm0Mk8AF8y1iAQro4=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=