Skip to content

Commit

Permalink
Print instructions after patches written to file (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslade authored Jun 4, 2020
1 parent 93bf999 commit 6333796
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 18 additions & 3 deletions cmd/src/actions_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -319,7 +334,7 @@ Format of the action JSON files:
}
}
} else {
logger.ActionSuccess(patches, false)
logger.ActionSuccess(patches)
}

tmpl, err := parseTemplate("{{friendlyPatchSetCreatedMessage .}}")
Expand Down
5 changes: 1 addition & 4 deletions cmd/src/actions_exec_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit 6333796

Please sign in to comment.