Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print instructions after patches written to file #216

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -104,15 +104,12 @@ 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
}
fmt.Fprintln(os.Stderr)
format := "✔ Action produced %d patches."
if newLines {
format = format + "\n\n"
}
hiGreen.Fprintf(os.Stderr, format, len(patches))
}

Expand Down