refactor(cli): extract commit result display and extend commit return with stats
This commit is contained in:
@@ -355,20 +355,32 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
function printCommitResult(
|
||||
result: { branch: string; hash: string; files: number; insertions: number; deletions: number },
|
||||
msg: string,
|
||||
) {
|
||||
console.log(`\n ${GREEN}${BOLD}✔ Committed successfully!${RESET}`);
|
||||
|
||||
const id = result.branch && result.hash
|
||||
? `${YELLOW}[${result.branch} ${result.hash}]${RESET}`
|
||||
: result.hash
|
||||
? `${YELLOW}${result.hash}${RESET}`
|
||||
: "";
|
||||
console.log(` ${id} ${msg}`);
|
||||
|
||||
const parts: string[] = [];
|
||||
if (result.files > 0) parts.push(`${YELLOW}${result.files} file${result.files > 1 ? "s" : ""} changed${RESET}`);
|
||||
if (result.insertions > 0) parts.push(`${GREEN}${result.insertions} insertion${result.insertions > 1 ? "s" : ""}(+)${RESET}`);
|
||||
if (result.deletions > 0) parts.push(`${RED}${result.deletions} deletion${result.deletions > 1 ? "s" : ""}(-)${RESET}`);
|
||||
if (parts.length > 0) console.log(` ${parts.join(", ")}`);
|
||||
}
|
||||
|
||||
const action = await confirmCommit(message);
|
||||
|
||||
if (action === "y") {
|
||||
try {
|
||||
const result = await commit(message);
|
||||
console.log(
|
||||
`\n ${GREEN}${BOLD}✔ Committed successfully!${RESET}`,
|
||||
);
|
||||
if (result.hash) {
|
||||
console.log(` ${YELLOW}${result.hash}${RESET} ${message}`);
|
||||
}
|
||||
if (result.summary) {
|
||||
console.log(` ${DIM}${result.summary}${RESET}`);
|
||||
}
|
||||
printCommitResult(result, message);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
` ${RED}Commit failed: ${err instanceof Error ? err.message : err}${RESET}`,
|
||||
@@ -380,15 +392,7 @@ async function main() {
|
||||
if (edited) {
|
||||
try {
|
||||
const result = await commit(edited);
|
||||
console.log(
|
||||
`\n ${GREEN}${BOLD}✔ Committed successfully!${RESET}`,
|
||||
);
|
||||
if (result.hash) {
|
||||
console.log(` ${YELLOW}${result.hash}${RESET} ${edited}`);
|
||||
}
|
||||
if (result.summary) {
|
||||
console.log(` ${DIM}${result.summary}${RESET}`);
|
||||
}
|
||||
printCommitResult(result, edited);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
` ${RED}Commit failed: ${err instanceof Error ? err.message : err}${RESET}`,
|
||||
|
||||
Reference in New Issue
Block a user