From 6f6674f8e67e380efe64cd53662f342cd4604a74 Mon Sep 17 00:00:00 2001 From: Ryan Slade Date: Thu, 4 Jun 2020 16:45:12 +0200 Subject: [PATCH] Print instructions after patches written to file (#216) --- cmd/src/actions_exec.go | 21 ++++++++++++++++++--- cmd/src/actions_exec_logger.go | 5 +---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/src/actions_exec.go b/cmd/src/actions_exec.go index abe5c27af8..cdb55beb59 100644 --- a/cmd/src/actions_exec.go +++ b/cmd/src/actions_exec.go @@ -295,9 +295,24 @@ Format of the action JSON files: os.Exit(1) } - logger.ActionSuccess(patches, true) + err = json.NewEncoder(outputWriter).Encode(patches) + if err != nil { + return errors.Wrap(err, "writing patches") + } + + logger.ActionSuccess(patches) + + if out, ok := outputWriter.(*os.File); ok && out == os.Stdout { + // Don't print instructions when piping + return nil + } + + // Print instructions when we've written patches to a file, even when not in verbose mode + fmt.Fprintf(os.Stderr, "\n\nPatches saved to %s, to create a patch set on your Sourcegraph instance please do the following:\n", *outputFlag) + fmt.Fprintln(os.Stderr, "\n ", color.HiCyanString("▶"), fmt.Sprintf("src campaign patchset create-from-patches < %s", *outputFlag)) + fmt.Fprintln(os.Stderr) - return json.NewEncoder(outputWriter).Encode(patches) + return nil } if err != nil { @@ -319,7 +334,7 @@ Format of the action JSON files: } } } else { - logger.ActionSuccess(patches, false) + logger.ActionSuccess(patches) } tmpl, err := parseTemplate("{{friendlyPatchSetCreatedMessage .}}") diff --git a/cmd/src/actions_exec_logger.go b/cmd/src/actions_exec_logger.go index 512ab31e7e..a82bed6ee8 100644 --- a/cmd/src/actions_exec_logger.go +++ b/cmd/src/actions_exec_logger.go @@ -105,16 +105,13 @@ func (a *actionLogger) ActionFailed(err error, patches []PatchInput) { } } -func (a *actionLogger) ActionSuccess(patches []PatchInput, newLines bool) { +func (a *actionLogger) ActionSuccess(patches []PatchInput) { if !a.verbose { return } a.out.Close() fmt.Fprintln(os.Stderr) format := "✔ Action produced %d patches." - if newLines { - format = format + "\n\n" - } hiGreen.Fprintf(os.Stderr, format, len(patches)) }