-
Notifications
You must be signed in to change notification settings - Fork 10
Default bare hunk to diff startup #157
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,15 @@ import { | |
| usesPipedPatchInput, | ||
| type ControllingTerminal, | ||
| } from "./terminal"; | ||
| import type { AppBootstrap, CliInput, ParsedCliInput, SessionCommandInput } from "./types"; | ||
| import type { | ||
| AppBootstrap, | ||
| CliInput, | ||
| PagerCommandInput, | ||
| ParsedCliInput, | ||
| SessionCommandInput, | ||
| } from "./types"; | ||
| import { canReloadInput } from "./watch"; | ||
| import { parseCli } from "./cli"; | ||
| import { parseCli, renderCliHelp } from "./cli"; | ||
|
|
||
| export type StartupPlan = | ||
| | { | ||
|
|
@@ -44,6 +50,7 @@ export interface StartupDeps { | |
| loadAppBootstrapImpl?: typeof loadAppBootstrap; | ||
| usesPipedPatchInputImpl?: typeof usesPipedPatchInput; | ||
| openControllingTerminalImpl?: typeof openControllingTerminal; | ||
| stdinIsTTY?: boolean; | ||
| } | ||
|
|
||
| /** Normalize startup work so help, pager, and app-bootstrap paths can be tested directly. */ | ||
|
|
@@ -60,8 +67,9 @@ export async function prepareStartupPlan( | |
| const loadAppBootstrapImpl = deps.loadAppBootstrapImpl ?? loadAppBootstrap; | ||
| const usesPipedPatchInputImpl = deps.usesPipedPatchInputImpl ?? usesPipedPatchInput; | ||
| const openControllingTerminalImpl = deps.openControllingTerminalImpl ?? openControllingTerminal; | ||
| const stdinIsTTY = deps.stdinIsTTY ?? Boolean(process.stdin.isTTY); | ||
|
|
||
| let parsedCliInput = await parseCliImpl(argv); | ||
| const parsedCliInput = await parseCliImpl(argv); | ||
|
|
||
| if (parsedCliInput.kind === "help") { | ||
| return { | ||
|
|
@@ -83,28 +91,51 @@ export async function prepareStartupPlan( | |
| }; | ||
| } | ||
|
|
||
| if (parsedCliInput.kind === "pager") { | ||
| const bareInvocation = parsedCliInput.kind === "bare"; | ||
| let appCliInput: CliInput | PagerCommandInput; | ||
|
|
||
| if (bareInvocation) { | ||
| // Keep bare `hunk` ergonomic in interactive shells while preserving pager-style stdin flows. | ||
| if (stdinIsTTY) { | ||
| appCliInput = { kind: "git", staged: false, options: {} }; | ||
| } else { | ||
| appCliInput = { kind: "pager", options: {} }; | ||
| } | ||
| } else if (parsedCliInput.kind === "pager") { | ||
| appCliInput = parsedCliInput; | ||
| } else { | ||
| appCliInput = parsedCliInput; | ||
| } | ||
|
|
||
| if (appCliInput.kind === "pager") { | ||
| const stdinText = await readStdinText(); | ||
|
|
||
| if (stdinText.length === 0 && bareInvocation) { | ||
| return { | ||
| kind: "help", | ||
| text: renderCliHelp(), | ||
| }; | ||
| } | ||
|
Comment on lines
+113
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Every other side-effectful operation in Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| if (!looksLikePatchInputImpl(stdinText)) { | ||
| return { | ||
| kind: "plain-text-pager", | ||
| text: stdinText, | ||
| }; | ||
| } | ||
|
|
||
| parsedCliInput = { | ||
| appCliInput = { | ||
| kind: "patch", | ||
| file: "-", | ||
| text: stdinText, | ||
| options: { | ||
| ...parsedCliInput.options, | ||
| ...appCliInput.options, | ||
| pager: true, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| const runtimeCliInput = resolveRuntimeCliInputImpl(parsedCliInput); | ||
| const runtimeCliInput = resolveRuntimeCliInputImpl(appCliInput); | ||
| const configured = resolveConfiguredCliInputImpl(runtimeCliInput); | ||
| const cliInput = configured.input; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else ifandelsebranchesBoth the
else if (parsedCliInput.kind === "pager")and the finalelsebranch do exactly the same thing (appCliInput = parsedCliInput). Sincehelp,mcp-serve,session, andbarehave all been handled above, the only remaining shapes areCliInput | PagerCommandInput, making the distinction between the two branches meaningless.