Skip to content

Commit 96891a5

Browse files
committed
fix: properly handle empty args to ensure CLI exits with code 0
The issue was that showHelpOrError was being called even when args were already handled by the early exit. Now we only call it when there are invalid args, not when there are no args. This fixes the CI test failures on Linux where empty args handling differs from macOS.
1 parent ec0d540 commit 96891a5

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@
218218
"Bash(git init:*)",
219219
"Bash(PROMPTCODE_TEST=1 promptcode cc --yes)",
220220
"Bash(PROMPTCODE_TEST=1 PROMPTCODE_MOCK_LLM=1 OPENAI_API_KEY=test-key ./dist/promptcode expert \"Test question\" --model gpt-5 --no-web-search --yes)",
221-
"Bash(OPENAI_API_KEY=\"\" ./dist/promptcode expert \"Test question\" --model gpt-5 --estimate-cost)"
221+
"Bash(OPENAI_API_KEY=\"\" ./dist/promptcode expert \"Test question\" --model gpt-5 --estimate-cost)",
222+
"Bash(git describe:*)"
222223
],
223224
"deny": [],
224225
"defaultMode": "acceptEdits",

packages/cli/src/index.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,10 @@ import { exitWithCode, EXIT_CODES } from './utils/exit-codes';
6969

7070

7171
/**
72-
* Show help when no valid command is provided
72+
* Show error for invalid command usage
7373
*/
7474
function showHelpOrError(args: string[]): void {
75-
// If no args provided, show help
76-
if (args.length === 0) {
77-
program.outputHelp();
78-
process.exit(0); // Exit cleanly after showing help
79-
}
80-
81-
// Otherwise show error for invalid usage
75+
// Show error for invalid usage
8276
console.error(chalk.red(`Error: Invalid usage. Please specify a command.\n`));
8377
console.error(chalk.yellow('Available commands:'));
8478
console.error(chalk.gray(' generate - Generate a prompt from selected files'));
@@ -606,10 +600,10 @@ if (args.includes('--update')) {
606600
// After converting --command to command, check if we have a known subcommand
607601
const hasSubcommand = args.length > 0 && knownCommands.includes(args[0]);
608602

609-
if (!hasSubcommand) {
610-
// No valid command found or no args provided, show help or error
603+
if (!hasSubcommand && args.length > 0) {
604+
// Invalid command found, show error
611605
showHelpOrError(args);
612-
} else {
606+
} else if (hasSubcommand) {
613607
// Start async update check - will show message at exit if update available
614608
startUpdateCheck();
615609

0 commit comments

Comments
 (0)