Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
KaminoRyo opened this issue Oct 24, 2023 · 0 comments
Open
1 of 3 tasks

Comments

@KaminoRyo
Copy link

KaminoRyo commented Oct 24, 2023

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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant