Skip to content

Option flag doesn't works when running commander from script using NPM #1262

@shahafa

Description

@shahafa

Hi,

I'm following the pizza example in the documentation

index.js

const { program } = require('commander');

program
  .option('-d, --debug', 'output extra debugging')
  .option('-s, --small', 'small pizza size')
  .option('-p, --pizza-type <type>', 'flavour of pizza');

program.parse(process.argv);

if (program.debug) console.log(program.opts());
console.log('pizza details:');
if (program.small) console.log('- small pizza size');
if (program.pizzaType) console.log(`- ${program.pizzaType}`);

package.json

{
  "name": "test",
  "scripts": {
    "start": "node index.js",
  },
  "dependencies": {
    "commander": "^5.1.0"
  }
}

when I'm running yarn start -p cheese everything works as expected and the console prints

pizza details:
- cheese

however when I'm running npm run start -p cheese the pizza type flag is missing, the console prints

pizza details:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions