Skip to content

Commit f46c1ec

Browse files
authored
Merge pull request #114 from kcmvp/pty
#113: disable pty on windows
2 parents b1dd884 + 9b460f0 commit f46c1ec

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

cmd/gbc/artifact/plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (plugin Plugin) install() (string, error) {
129129
return pair
130130
})
131131
task := fmt.Sprintf("%s installation", plugin.Name())
132-
if err := StreamCmdOutput(cmd, task, func(msg string) string {
132+
if err := PtyCmdOutput(cmd, task, func(msg string) string {
133133
return ""
134134
}); err != nil {
135135
return tempGoPath, err
@@ -160,7 +160,7 @@ func (plugin Plugin) Execute() error {
160160
}
161161
// always use absolute path
162162
pCmd := exec.Command(filepath.Join(GoPath(), plugin.Binary()), strings.Split(plugin.Args, " ")...) //nolint #gosec
163-
if err := StreamCmdOutput(pCmd, plugin.taskName(), nil); err != nil {
163+
if err := PtyCmdOutput(pCmd, plugin.taskName(), nil); err != nil {
164164
return err
165165
}
166166
if pCmd.ProcessState.ExitCode() != 0 {

cmd/gbc/artifact/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func init() {
9292
log.Fatal(color.RedString("please execute command in project root directory %s", string(output)))
9393
}
9494
cfg := &packages.Config{
95-
Mode: packages.NeedName | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedFiles | packages.NeedTypesInfo | packages.NeedDeps | packages.NeedImports | packages.NeedSyntax,
95+
Mode: packages.NeedName | packages.NeedTypes | packages.NeedFiles | packages.NeedTypesInfo,
9696
Dir: project.root,
9797
}
9898
project.pkgs, err = packages.Load(cfg, "./...")

cmd/gbc/artifact/multiple_writer.go renamed to cmd/gbc/artifact/pty_writer.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package artifact
33
import (
44
"bufio"
55
"fmt"
6+
"io"
67
"os"
78
"os/exec"
89
"path/filepath"
@@ -18,17 +19,19 @@ import (
1819

1920
type consoleFormatter func(msg string) string
2021

21-
func StreamCmdOutput(cmd *exec.Cmd, task string, formatter consoleFormatter) error {
22+
func PtyCmdOutput(cmd *exec.Cmd, task string, formatter consoleFormatter) error {
2223
// Start the command with a pty
23-
var scanner *bufio.Scanner
24-
if ptmx, err := pty.Start(cmd); err == nil {
25-
scanner = bufio.NewScanner(ptmx)
26-
defer ptmx.Close()
27-
} else if rd, err := cmd.StdoutPipe(); err == nil {
28-
scanner = bufio.NewScanner(rd)
29-
} else {
24+
rc, err := func() (io.ReadCloser, error) {
25+
if Windows() {
26+
return cmd.StdoutPipe()
27+
}
28+
return pty.Start(cmd)
29+
}()
30+
if err != nil {
3031
return err
3132
}
33+
defer rc.Close()
34+
scanner := bufio.NewScanner(rc)
3235
color.Green("start %s ......\n", task)
3336
// Create a file to save the output
3437
log, err := os.Create(filepath.Join(CurProject().Target(), fmt.Sprintf("%s.log", strings.ReplaceAll(task, " ", "_"))))

cmd/gbc/command/build_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func cleanAction(_ *cobra.Command, _ ...string) error {
126126
func testAction(_ *cobra.Command, _ ...string) error {
127127
coverProfile := fmt.Sprintf("-coverprofile=%s/cover.out", artifact.CurProject().Target())
128128
testCmd := exec.Command("go", []string{"test", "-v", coverProfile, "./..."}...) //nolint
129-
return artifact.StreamCmdOutput(testCmd, "test", nil)
129+
return artifact.PtyCmdOutput(testCmd, "test", nil)
130130
}
131131

132132
func coverReport(_ *cobra.Command, _ ...string) error {

0 commit comments

Comments
 (0)