From 7fa9b7214485a91b5415d1d3dc315e71e7c121b1 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 10 Mar 2020 23:06:00 -0400 Subject: [PATCH] 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 --- plugins/apps/functions.go | 4 +++- plugins/common/common.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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"