diff --git a/plugins/apps/functions.go b/plugins/apps/functions.go index e4472df4b..1d4b1fdca 100644 --- a/plugins/apps/functions.go +++ b/plugins/apps/functions.go @@ -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 createApp(appName) + return common.SuppressOutput(func() error { + return createApp(appName) + }) } diff --git a/plugins/common/common.go b/plugins/common/common.go index b670e24e5..644fdf77e 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -18,6 +18,8 @@ import ( sh "github.com/codeskyblue/go-sh" ) +type errfunc func() error + // ShellCmd represents a shell command to be run for dokku type ShellCmd struct { Env map[string]string @@ -533,6 +535,25 @@ func StripInlineComments(text string) string { 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 func ToBool(s string) bool { return s == "true"