Skip to content

Commit cfb7695

Browse files
committed
fix(exec): fix group exec failed
fix group exec failed Signed-off-by: mritd <[email protected]>
1 parent 7dd232e commit cfb7695

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pkg/core/exec.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// Exec batch execution of commands
24-
func Exec(cmd, tagOrName string, single, ping bool) {
24+
func Exec(cmd, tagOrName string, execGroup, ping bool) {
2525
// use context to manage goroutine
2626
ctx, cancel := context.WithCancel(context.Background())
2727
defer cancel()
@@ -38,10 +38,10 @@ func Exec(cmd, tagOrName string, single, ping bool) {
3838
}()
3939

4040
// single server exec
41-
if single {
41+
if !execGroup {
4242
server, err := findServerByName(tagOrName)
4343
common.CheckAndExit(err)
44-
err = exec(ctx, cmd, server, single, ping)
44+
err = exec(ctx, cmd, server, false, ping)
4545
common.PrintErr(err)
4646
} else {
4747
// multiple servers
@@ -56,7 +56,7 @@ func Exec(cmd, tagOrName string, single, ping bool) {
5656
// because it takes time for ssh to establish a connection
5757
go func(s *Server) {
5858
defer execWg.Done()
59-
err = exec(ctx, cmd, s, single, false)
59+
err = exec(ctx, cmd, s, true, false)
6060
common.PrintErrWithPrefix(s.Name, err)
6161
}(s)
6262
}
@@ -66,7 +66,7 @@ func Exec(cmd, tagOrName string, single, ping bool) {
6666

6767
// single server execution command
6868
// since multiple tasks are executed async, the error is returned using channel
69-
func exec(ctx context.Context, cmd string, s *Server, single, ping bool) error {
69+
func exec(ctx context.Context, cmd string, s *Server, colorPrint, ping bool) error {
7070
// get ssh client
7171
sshClient, err := s.sshClient(ping)
7272
if err != nil {
@@ -97,7 +97,7 @@ func exec(ctx context.Context, cmd string, s *Server, single, ping bool) error {
9797
<-sshSession.Ready()
9898

9999
// read from sshSession.Stdout and print to os.stdout
100-
if single {
100+
if !colorPrint {
101101
_, _ = io.Copy(os.Stdout, sshSession.Stdout)
102102
} else {
103103
buf := bufio.NewReader(sshSession.Stdout)

pkg/core/ping.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ func Ping(name string) {
1919
cmd.Stdout = os.Stdout
2020
common.CheckAndExit(cmd.Run())
2121
} else {
22-
Exec("ping "+server.Address, name, true, true)
22+
Exec("ping "+server.Address, name, false, true)
2323
}
2424
}

0 commit comments

Comments
 (0)