-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcmd.go
54 lines (44 loc) · 1.02 KB
/
mcmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"strings"
"syscall"
"github.com/fatih/color"
)
var (
errLogger = log.New(os.Stderr, "", 0)
COLORS = []func(...interface{}) string{
color.New(color.FgGreen).SprintFunc(),
color.New(color.FgRed).SprintFunc(),
color.New(color.FgBlue).SprintFunc(),
color.New(color.FgYellow).SprintFunc(),
color.New(color.FgMagenta).SprintFunc(),
color.New(color.FgWhite).SprintFunc(),
color.New(color.FgCyan).SprintFunc(),
color.New(color.FgBlack).SprintFunc(),
}
)
func main() {
flag.Parse()
config := loadConfig()
command := remoteCommand()
done := runCommands(command, config)
signals := make(chan os.Signal)
signal.Notify(signals, syscall.SIGINT)
select {
case <-signals:
fmt.Println() // clean up for the next prompt
case <-done:
}
}
func remoteCommand() string {
return strings.Join(flag.Args()[1:], " ")
}
func formatOutput(hostIndex int, host, str string) string {
colorFunc := COLORS[hostIndex%len(COLORS)]
return colorFunc("["+host+"] ") + str
}