Skip to content

The behavior of the "parse" function when used without arguments is strange. #158

@KaminoRyo

Description

@KaminoRyo

Issue Type

  • Bug Report
  • Feature Request
  • Other

Hi. I am attempting to create my first Node.js CLI program.

const cli = cac("sample-app");
cli.command("hello", "say hello world").action(() => {
  console.log("Hello World!");
});
const parsed = cli.parse();
console.log(parsed);

I ran this sample code using the npx vite-node index.ts hello command.

Expected

"Hello World!" is being printed.

Actual

"Hello World!" is not being printed.There are no errors.The help() and version() commands are working as expected.

Possible Solutions

Upon investigation, I found that using parse(process.argv) results in "Hello World!" being printed when no arguments are provided, while the parsed object logged in both cases shows the differences:

No arguments provided (incorrect)

{ args: [ 'index.ts', 'hello' ], options: { '--': [] } }

Using process.argv as arguments (correct)

{ args: [], options: { '--': [] } }

It appears that the code processes arguments differently when no arguments are provided, and it seems to be related to Deno's Deno.args.
I'm not familiar with Deno, so this difference is a puzzling.

Info

  • CAC version: 6.7.14
  • Reproduction link:

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