refactor(cli): replace process.exit prompts with interactive selection for empty states

This commit is contained in:
2026-06-12 00:36:01 +08:00
parent 962b76d20f
commit 14df49b110
+28 -15
View File
@@ -611,11 +611,14 @@ async function showMenu(): Promise<void> {
if (selected === null || selected === BACK) return; if (selected === null || selected === BACK) return;
if (selected === "commit") await handleCommit(false, false); const result =
else if (selected === "pr") await handlePR(false); selected === "commit"
else await handleConfig(); ? await handleCommit(false, false)
: selected === "pr"
? await handlePR(false)
: await handleConfig();
return; if (result !== "back") return;
} }
} }
@@ -660,9 +663,13 @@ async function handleCommit(
const unstagedFiles = await getUnstagedFiles(); const unstagedFiles = await getUnstagedFiles();
if (stagedFiles.length === 0 && unstagedFiles.length === 0) { if (stagedFiles.length === 0 && unstagedFiles.length === 0) {
console.log(`\n ${YELLOW}Nothing to commit.${RESET}`); const choice = await selectOne({
await ask(` ${DIM}Press Enter to exit...${RESET}`); title: "Nothing to commit",
process.exit(0); subtitle: "No staged or unstaged changes.",
items: [{ label: "Back", value: "back" as const }],
});
if (choice === null) process.exit(0);
return "done";
} }
if (unstagedFiles.length > 0) { if (unstagedFiles.length > 0) {
@@ -685,9 +692,13 @@ async function handleCommit(
const diff = await getStagedDiff(); const diff = await getStagedDiff();
if (!diff) { if (!diff) {
console.log(`\n ${YELLOW}No staged changes to commit.${RESET}`); const choice = await selectOne({
await ask(` ${DIM}Press Enter to exit...${RESET}`); title: "Nothing to commit",
process.exit(0); subtitle: "No staged changes to commit.",
items: [{ label: "Back", value: "back" as const }],
});
if (choice === null) process.exit(0);
return "done";
} }
const MAX_DIFF_SIZE = 15000; const MAX_DIFF_SIZE = 15000;
@@ -815,11 +826,13 @@ async function handlePR(draft: boolean): Promise<"done" | "back"> {
const commits = await getBranchCommits(baseBranch); const commits = await getBranchCommits(baseBranch);
if (commits.length === 0) { if (commits.length === 0) {
console.error( const choice = await selectOne({
`\n ${YELLOW}No commits on ${branchName} compared to ${baseBranch}. Commit something first.${RESET}`, title: "No commits to compare",
); subtitle: `No commits on ${branchName} compared to ${baseBranch}. Commit something first.`,
await ask(` ${DIM}Press Enter to exit...${RESET}`); items: [{ label: "Back", value: "back" as const }],
process.exit(0); });
if (choice === null) process.exit(0);
return "done";
} }
console.log( console.log(