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

Command is not found in deno - incorrect arguments argv handling #69

Closed
1 of 3 tasks
drawveloper opened this issue Mar 8, 2020 · 1 comment · Fixed by #70
Closed
1 of 3 tasks

Command is not found in deno - incorrect arguments argv handling #69

drawveloper opened this issue Mar 8, 2020 · 1 comment · Fixed by #70
Labels

Comments

@drawveloper
Copy link
Contributor

drawveloper commented Mar 8, 2020

Issue Type

  • Bug Report
  • Feature Request
  • Other

Expected

A simple cac cli written in node with one command should find the command when called.

e.g.

Create a file cli.ts with contents:


const cli = cac('act')
cli
  .command('install [...apps]', 'Install apps')
  .action((apps: any, options: any) => {
    console.log('Wow! Deno cli!', apps, options)
  })

cli.parse()

Then run deno install cli cli.ts and finally cli install a

Expected behavior: the console.log should execute

Actual

Nothing happens! Because the library cannot find the command given incorrect argv handling.

If you call it with an extra argument, though it works:

cli whatever install a

Result: console.log is called.

Possible Solutions

I believe this happened because of this change: denoland/deno#2123 (comment)

Now, Deno.args only has the actual arguments.

This is the source of the problem:

export const processArgs = deno ? ['deno'].concat(Deno.args) : process.argv

In node, the argv process has two "useless" elements in the beginning: the node executable itself, and the path to the script which started execution:
https://nodejs.org/docs/latest/api/process.html#process_process_argv

And finally, here is where we "remove" those two useless args, but they're not useless for Deno! They are the args.

cac/src/CAC.ts

Line 178 in aa8f868

const parsed = this.mri(argv.slice(2), command)

There are some possible solutions. Simplest would be to add the "script path" to the processArgs variable, to be "backwards compatible" with node code. Do you want me to PR that, or do you see a better alternative?

Thanks for the great lib!

Info

@egoist
Copy link
Collaborator

egoist commented Mar 20, 2020

🎉 This issue has been resolved in version 6.5.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants