Skip to content

Bug: unknown CLI flags exit with code 0 instead of a failure code #212

@codxbrexx

Description

@codxbrexx

What's happening

If you pass an unrecognized flag (e.g. metacall-deploy --not-a-real-flag),
the CLI prints a warning and the help text, but exits with code 0.
This breaks any CI pipeline or shell script that checks the exit code to detect invalid usage.

Steps to reproduce

metacall-deploy --not-a-real-flag
echo $? 

What you'd expect

Exit code 1 (or any non-zero) when an unknown flag is passed.

What actually happens

process.exit(0) because handleUnknownArgs() calls printHelp() which always exits with ErrorCode.Ok.

Relevant files:

  • src/cli/unknown.ts// always calls printHelp()
  • src/help.ts // always exits with ErrorCode.Ok

The fix

Add an optional exit code param to printHelp:

// src/help.ts
export const printHelp = (exitCode = ErrorCode.Ok) => {
    // ...
    process.exit(exitCode);
};

Then call it with 1 from the unknown-args path:

// src/cli/unknown.ts
printHelp(1);

Keep 0 only for explicit --help. Happy to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions