@@ -21,7 +21,7 @@ import (
21
21
)
22
22
23
23
// Exec batch execution of commands
24
- func Exec (cmd , tagOrName string , single , ping bool ) {
24
+ func Exec (cmd , tagOrName string , execGroup , ping bool ) {
25
25
// use context to manage goroutine
26
26
ctx , cancel := context .WithCancel (context .Background ())
27
27
defer cancel ()
@@ -38,10 +38,10 @@ func Exec(cmd, tagOrName string, single, ping bool) {
38
38
}()
39
39
40
40
// single server exec
41
- if single {
41
+ if ! execGroup {
42
42
server , err := findServerByName (tagOrName )
43
43
common .CheckAndExit (err )
44
- err = exec (ctx , cmd , server , single , ping )
44
+ err = exec (ctx , cmd , server , false , ping )
45
45
common .PrintErr (err )
46
46
} else {
47
47
// multiple servers
@@ -56,7 +56,7 @@ func Exec(cmd, tagOrName string, single, ping bool) {
56
56
// because it takes time for ssh to establish a connection
57
57
go func (s * Server ) {
58
58
defer execWg .Done ()
59
- err = exec (ctx , cmd , s , single , false )
59
+ err = exec (ctx , cmd , s , true , false )
60
60
common .PrintErrWithPrefix (s .Name , err )
61
61
}(s )
62
62
}
@@ -66,7 +66,7 @@ func Exec(cmd, tagOrName string, single, ping bool) {
66
66
67
67
// single server execution command
68
68
// 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 {
70
70
// get ssh client
71
71
sshClient , err := s .sshClient (ping )
72
72
if err != nil {
@@ -97,7 +97,7 @@ func exec(ctx context.Context, cmd string, s *Server, single, ping bool) error {
97
97
<- sshSession .Ready ()
98
98
99
99
// read from sshSession.Stdout and print to os.stdout
100
- if single {
100
+ if ! colorPrint {
101
101
_ , _ = io .Copy (os .Stdout , sshSession .Stdout )
102
102
} else {
103
103
buf := bufio .NewReader (sshSession .Stdout )
0 commit comments