From 640fd6a8d7bbea6311778860daf75d4cbe9d2ce2 Mon Sep 17 00:00:00 2001 From: Prathamesh Hukkeri Date: Mon, 27 Jul 2026 17:40:46 +0530 Subject: [PATCH] fix(cli): exit with non-zero code for unknown flags The CLI was exiting with code 0 when unknown flags were passed, breaking CI pipelines and shell scripts that check exit codes. Changes: - Add UnknownFlag error code to ErrorCode enum - Add optional exitCode parameter to printHelp() - Exit with ErrorCode.UnknownFlag when unknown flags are detected - Keep exit code 0 for explicit --help flag Fixes #212 --- src/cli/unknown.ts | 3 +++ src/deploy.ts | 13 +++++++------ src/help.ts | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cli/unknown.ts b/src/cli/unknown.ts index 668521e..4406a94 100644 --- a/src/cli/unknown.ts +++ b/src/cli/unknown.ts @@ -1,3 +1,4 @@ +import { ErrorCode } from '../deploy'; import { printHelp } from '../help'; import args from './args'; import { warn } from './messages'; @@ -10,6 +11,8 @@ export const handleUnknownArgs = (): void => { ', ' )} does not exist as a valid command.`; warn(message); + printHelp(ErrorCode.UnknownFlag); + return; } printHelp(); diff --git a/src/deploy.ts b/src/deploy.ts index 45e9b64..93d11f3 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -29,12 +29,13 @@ import { filterFiles, getEnv, loadFilesToRun, zip } from './utils'; export enum ErrorCode { Ok = 0, - NotDirectoryRootPath = 1, - EmptyRootPath = 2, - NotFoundRootPath = 3, - AccountDisabled = 4, - DeployPackageFailed = 5, - DeployRepositoryFailed = 6 + UnknownFlag = 1, + NotDirectoryRootPath = 2, + EmptyRootPath = 3, + NotFoundRootPath = 4, + AccountDisabled = 5, + DeployPackageFailed = 6, + DeployRepositoryFailed = 7 } export const deployPackage = async ( diff --git a/src/help.ts b/src/help.ts index 87b193b..c6da48e 100644 --- a/src/help.ts +++ b/src/help.ts @@ -62,7 +62,7 @@ Examples: For more information, visit: https://github.com/metacall/deploy `; -export const printHelp = (): void => { +export const printHelp = (exitCode: ErrorCode = ErrorCode.Ok): void => { console.log(helpText); - return process.exit(ErrorCode.Ok); + return process.exit(exitCode); };