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

NPM arg passing issue with command style syntax #1182

Closed
quetzalsly opened this issue Feb 8, 2020 · 4 comments
Closed

NPM arg passing issue with command style syntax #1182

quetzalsly opened this issue Feb 8, 2020 · 4 comments

Comments

@quetzalsly
Copy link

I am having some issues with 5.0.0:

  1. The -v does not work, only --version works like this:
program
  .version('1.0.0')
  .description('Test');
  1. The commands syntax does not seem to work with the npm argument passing system:
"scripts": {
    "program": "cross-env NODE_ENV=production node ./src/program/main.js",
    "test:program": "npm run program -- test"
  },

program.command('test')
  .description('Test')
  .action(async function()
  {
    await something();
  });

await program.parseAsync(process.argv);

Before I used commands, I used --arg style and test:program passed it along like -- --arg and it all worked fine.

@shadowspawn
Copy link
Collaborator

  1. Big -V not small -v? As seen in the help:
  -V, --version  output the version number
  1. Quite a lot of programs involved in the processing there, but don't think Commander is the problem.

What are you typing on command line, and what is not working?

For debugging, putting in a line to log the arguments early in the program is often helpful to narrow down what is reaching the node program. i.e.

console.log(process.argv);

@quetzalsly
Copy link
Author

  1. Solved thanks :) why not small v though? other programs use small v don't they?
  2. Here is the console log at start of main:
[
  'E:\\Node\\node.exe',
  'E:\\Program\\program\\src\\program\\main.js',
  'test'
]

Log shows something weird here:

unsafe-perm in lifecycle true
Returned: code: 1  signal: null
npm\node_modules\npm-lifecycle\index.js:332:16

The thing is it was working perfectly with the --arg, what could possibly be causing the issue with using commands instead of the standard way? Would really love to solve this somehow :(

@shadowspawn
Copy link
Collaborator

shadowspawn commented Feb 9, 2020

  1. Some programs do use -v for version, but many use -V and leave -v for verbose or other purposes.

You can change the flags by using `.version(version, flags)'
Related: #560

  1. So test is getting passed into the program, which is good (and reassuring since was working previously with --arg).

What happens when you call your program directly?

node ./src/program/main.js test

@quetzalsly
Copy link
Author

Thanks, I understand about the V now. I deleted node_modules and reinstalled it and everything suddenly started working... I think the issue was npm all along. Thanks for your help anyway! really loving the library.

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

2 participants