Skip to content

Commit 6f6674f

Browse files
authored
Print instructions after patches written to file (#216)
1 parent fd4e022 commit 6f6674f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

cmd/src/actions_exec.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,24 @@ Format of the action JSON files:
295295
os.Exit(1)
296296
}
297297

298-
logger.ActionSuccess(patches, true)
298+
err = json.NewEncoder(outputWriter).Encode(patches)
299+
if err != nil {
300+
return errors.Wrap(err, "writing patches")
301+
}
302+
303+
logger.ActionSuccess(patches)
304+
305+
if out, ok := outputWriter.(*os.File); ok && out == os.Stdout {
306+
// Don't print instructions when piping
307+
return nil
308+
}
309+
310+
// Print instructions when we've written patches to a file, even when not in verbose mode
311+
fmt.Fprintf(os.Stderr, "\n\nPatches saved to %s, to create a patch set on your Sourcegraph instance please do the following:\n", *outputFlag)
312+
fmt.Fprintln(os.Stderr, "\n ", color.HiCyanString("▶"), fmt.Sprintf("src campaign patchset create-from-patches < %s", *outputFlag))
313+
fmt.Fprintln(os.Stderr)
299314

300-
return json.NewEncoder(outputWriter).Encode(patches)
315+
return nil
301316
}
302317

303318
if err != nil {
@@ -319,7 +334,7 @@ Format of the action JSON files:
319334
}
320335
}
321336
} else {
322-
logger.ActionSuccess(patches, false)
337+
logger.ActionSuccess(patches)
323338
}
324339

325340
tmpl, err := parseTemplate("{{friendlyPatchSetCreatedMessage .}}")

cmd/src/actions_exec_logger.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,13 @@ func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
105105
}
106106
}
107107

108-
func (a *actionLogger) ActionSuccess(patches []PatchInput, newLines bool) {
108+
func (a *actionLogger) ActionSuccess(patches []PatchInput) {
109109
if !a.verbose {
110110
return
111111
}
112112
a.out.Close()
113113
fmt.Fprintln(os.Stderr)
114114
format := "✔ Action produced %d patches."
115-
if newLines {
116-
format = format + "\n\n"
117-
}
118115
hiGreen.Fprintf(os.Stderr, format, len(patches))
119116
}
120117

0 commit comments

Comments
 (0)