diff --git a/src/cli.ts b/src/cli.ts index 3e64327..550e622 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -57,11 +57,13 @@ export async function main(argv: string[]): Promise { try { await program.parseAsync(argv) } catch (err) { - if ( - err instanceof CommanderError && - (err.code === 'commander.helpDisplayed' || err.code === 'commander.version') - ) { - return + if (err instanceof CommanderError) { + if (err.code === 'commander.helpDisplayed' || err.code === 'commander.version') { + return + } + + console.error(err.message) + process.exit(err.exitCode || 1) } if (err instanceof ShpeckError || err instanceof GitError) { diff --git a/test/cli-smoke.test.ts b/test/cli-smoke.test.ts index 269b9d0..b3e9ff7 100644 --- a/test/cli-smoke.test.ts +++ b/test/cli-smoke.test.ts @@ -15,6 +15,18 @@ describe('cli smoke', () => { expect(stdout).toContain('Usage: shpeck') }) + it('does not print stack trace when no args', async () => { + const { exitCode, stdout, stderr } = await runCommand(['bun', cliPath], { + cwd: repoRoot, + allowNonZeroExit: true, + }) + + expect(exitCode).toBeGreaterThan(0) + expect(stderr).toContain('Usage: shpeck') + expect(stderr).not.toContain('Error:') + expect(stderr).not.toContain('at ') + }) + it('fails on unknown command', async () => { const { exitCode, stderr } = await runCommand(['bun', cliPath, 'nope'], { cwd: repoRoot,