From 9640dc509baccd2afc65a4167a64cc6024ff9faa Mon Sep 17 00:00:00 2001 From: syedahmedkhaderi Date: Tue, 19 May 2026 21:02:38 +0300 Subject: [PATCH] feat(cli): add --dry-run flag to preview commit message without committing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a --dry-run option that runs the full analysis and message generation pipeline, prints the resulting commit message to stdout, then exits with code 0 — skipping the interactive prompt and git commit entirely. Closes #29. Co-Authored-By: Claude Sonnet 4.6 --- bin/smartcommit.ts | 3 ++- src/index.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/smartcommit.ts b/bin/smartcommit.ts index 04817cc..fc54af7 100644 --- a/bin/smartcommit.ts +++ b/bin/smartcommit.ts @@ -9,7 +9,8 @@ program .version(pkg.version) .option("--ai", "Enhance commit message using AI") .option("--auto", "Auto accept commit without confirmation") - .option("--model ", "Specify Ollama model"); + .option("--model ", "Specify Ollama model") + .option("--dry-run", "Print the generated commit message and exit without committing"); program.action(async (options) => { await run(options); }); diff --git a/src/index.ts b/src/index.ts index e3828e8..2f4d790 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ interface CliOptions { ai?: boolean; model?: string; auto?: boolean; + dryRun?: boolean; [key: string]: unknown; } @@ -134,6 +135,12 @@ export async function run(options: CliOptions) { process.exit(1); } + // Dry run: print message and exit without committing + if (options.dryRun) { + console.log("\n" + commitMessage + "\n"); + process.exit(0); + } + // Confirmation flow let finalMessage: string;