feat: suppress the output of createApp

A git push requires that the first four bytes should be the line length, so not suppressing the output results in a partially failed deploy.

https://stackoverflow.com/a/8175315/1515875
This commit is contained in:
Jose Diaz-Gonzalez committed 2020-03-10 23:06:00 -04:00
1 parent 62a361cbe0
commit 7fa9b72144
2 files changed
+24 -1

No files matched your search

+3 -1
View File
@@ -155,5 +155,7 @@ func maybeCreateApp(appName string) error {
return fmt.Errorf("Re-enable app auto-creation or create an app with 'dokku apps:create %s'", appName) return fmt.Errorf("Re-enable app auto-creation or create an app with 'dokku apps:create %s'", appName)
} }
return createApp(appName) return common.SuppressOutput(func() error {
return createApp(appName)
})
} }
+21
View File
@@ -18,6 +18,8 @@ import (
sh "github.com/codeskyblue/go-sh" sh "github.com/codeskyblue/go-sh"
) )
type errfunc func() error
// ShellCmd represents a shell command to be run for dokku // ShellCmd represents a shell command to be run for dokku
type ShellCmd struct { type ShellCmd struct {
Env map[string]string Env map[string]string
@@ -533,6 +535,25 @@ func StripInlineComments(text string) string {
return strings.TrimSpace(string(bytes)) return strings.TrimSpace(string(bytes))
} }
// SuppressOutput suppresses the output of a function unless there is an error
func SuppressOutput(f errfunc) error {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
err := f()
w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout
if err != nil {
fmt.Printf(string(out[:]))
}
return err
}
// ToBool returns a bool value for a given string // ToBool returns a bool value for a given string
func ToBool(s string) bool { func ToBool(s string) bool {
return s == "true" return s == "true"