diff --git a/main.go b/main.go index 11f04f6..4519db1 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os/exec" "bufio" + "flag" ) var mongoBasePath = "/opt/my-mongo" @@ -13,36 +14,62 @@ var numberOfContainers int = 5 var maxMemAllocPercent int = 95 var mongoInitdbRootUsername = "sasha" var mongoInitdbRootPassword = "12345" +var verbosePtr = flag.Bool("v", false, "boolean") func ExecSystem(command string) { - cmd := exec.Command("/usr/bin/bash", "-c", command) - stdout, err := cmd.StdoutPipe() - if err != nil { - fmt.Println("Error obtaining stdout pipe:", err) - return - } - // Start the command - if err := cmd.Start(); err != nil { - fmt.Println("Error starting command:", err) - return - } + if *verbosePtr{ + cmd := exec.Command("/usr/bin/bash", "-c", command) + + stdout, err := cmd.StdoutPipe() + if err != nil { + fmt.Println("Error obtaining stdout pipe:", err) + return + } - // Read the output line by line - scanner := bufio.NewScanner(stdout) - for scanner.Scan() { - fmt.Println(scanner.Text()) - } + stderr, err := cmd.StderrPipe() + if err != nil { + fmt.Println("Error obtaining stderr pipe:", err) + return + } - // Check for any errors - if err := scanner.Err(); err != nil { - fmt.Println("Error reading command output:", err) - } - // Wait for the command to finish - if err := cmd.Wait(); err != nil { - fmt.Println("Error waiting for command:", err) - } + // Start the command + if err := cmd.Start(); err != nil { + fmt.Println("Error starting command:", err) + return + } + + // Read the output line by line + stdoutScanner := bufio.NewScanner(stdout) + stderrScanner := bufio.NewScanner(stderr) + for stdoutScanner.Scan() { + fmt.Println(stdoutScanner.Text()) + } + for stderrScanner.Scan() { + fmt.Println(stderrScanner.Text()) + } + } else { + cmd := exec.Command("/usr/bin/bash", "-c", command) + stderr, err := cmd.StderrPipe() + if err != nil { + fmt.Println("Error obtaining stderr pipe:", err) + return + } + + // Start the command + if err := cmd.Start(); err != nil { + fmt.Println("Error starting command:", err) + return + } + + // Read the output line by line + stderrScanner := bufio.NewScanner(stderr) + + for stderrScanner.Scan() { + fmt.Println(stderrScanner.Text()) + } + } } func genKeys() { @@ -55,6 +82,7 @@ func genKeys() { } func main() { + flag.Parse() checkRoot() checkSettings() instDeps()