// Run a command without showing a prompt or the output to the user func (b *Bootstrap) runCommandSilentlyAndCaptureOutput(command string, args ...string) (string, error) { cmd := b.newCommand(command, args...) var buffer bytes.Buffer _, err := shell.Run(cmd, &shell.Config{Writer: &buffer}) return strings.TrimSpace(buffer.String()), err }
// Run a command and return it's exit status func (b *Bootstrap) runCommandGracefully(command string, args ...string) int { cmd := b.newCommand(command, args...) promptf("%s", cmd) process, err := shell.Run(cmd, &shell.Config{Writer: os.Stdout}) checkShellError(err, cmd) return process.ExitStatus() }
// Runs a script on the file system func (b *Bootstrap) runScript(command string) int { var cmd *shell.Command if runtime.GOOS == "windows" { cmd = b.newCommand(command) } else { // If you run a script on Linux that doesn't have the // #!/bin/bash thingy at the top, it will fail to run with a // "exec format error" error. You can solve it by adding the // #!/bin/bash line to the top of the file, but that's // annoying, and people generally forget it, so we'll make it // easy on them and add it for them here. // // We also need to make sure the script we pass has quotes // around it, otherwise `/bin/bash -c run script with space.sh` // fails. cmd = b.newCommand("/bin/bash", "-c", `"`+strings.Replace(command, `"`, `\"`, -1)+`"`) } process, err := shell.Run(cmd, &shell.Config{Writer: os.Stdout, PTY: b.RunInPty}) checkShellError(err, cmd) return process.ExitStatus() }