diff --git a/cmd/app.go b/cmd/app.go index 39738bc..c55a8a7 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -2,10 +2,24 @@ package cmd import ( "fmt" + "io" "github.com/urfave/cli/v2" ) +func init() { + // Override the default HelpPrinter to write directly to the provided + // io.Writer using fmt.Fprint. This avoids any OS-specific pager or + // man-page lookup and ensures --help works identically on Windows, + // macOS, and Linux. + // HelpPrinterCustom renders the help template directly into w via + // text/template.Execute — no external pager, man-page, or shell command + // is invoked, which is what makes this safe on Windows/PowerShell. + cli.HelpPrinter = func(w io.Writer, templ string, data interface{}) { + cli.HelpPrinterCustom(w, templ, data, nil) + } +} + // Handlers contains injected command actions so CLI wiring can live outside main. type Handlers struct { RunReviewSimple cli.ActionFunc diff --git a/internal/appcore/review_runtime.go b/internal/appcore/review_runtime.go index c18ce75..127800c 100644 --- a/internal/appcore/review_runtime.go +++ b/internal/appcore/review_runtime.go @@ -170,7 +170,7 @@ func runReviewWithOptions(opts reviewopts.Options) error { return fmt.Errorf("failed to collect diff for vouch: %w", diffErr) } if len(diffContent) == 0 { - return fmt.Errorf("no diff content to vouch for") + return fmt.Errorf("%s", noDiffMessage(opts.DiffSource)) } parsedFiles, parseErr := parseDiffToFiles(diffContent) if parseErr != nil { @@ -271,7 +271,7 @@ func runReviewWithOptions(opts reviewopts.Options) error { } if len(diffContent) == 0 { - return fmt.Errorf("no diff content collected") + return fmt.Errorf("%s", noDiffMessage(opts.DiffSource)) } var fakeBaseFiles []reviewmodel.DiffReviewFileResult @@ -1368,6 +1368,25 @@ func collectDiffWithOptions(opts reviewopts.Options) ([]byte, error) { } } +// noDiffMessage returns a beginner-friendly error string tailored to the +// diff source that produced no content. +func noDiffMessage(diffSource string) string { + switch diffSource { + case "staged": + return "No staged changes found. Please stage your files using `git add ` before running a review." + case "working": + return "No working-tree changes found. Make some edits before running a review." + case "commit": + return "The specified commit(s) produced an empty diff. Verify the commit reference and try again." + case "range": + return "The specified range produced an empty diff. Verify the range and try again." + case "file": + return "The provided diff file is empty. Provide a non-empty diff file." + default: + return "No diff content collected." + } +} + // runCommitAndMaybePush commits the staged changes and optionally pushes with safety checks. func runCommitAndMaybePush(message string, push bool, verbose bool) error { msg := strings.TrimSpace(message)