JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 720
  • Score
    100M100P100Q104119F
  • License MIT

the complete solution for node.js command-line programs

Package Exports

  • safe-commander

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (safe-commander) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

safe Commander.js

npm version npm downloads

Commander.js has a major design flaw in the option API, such that options like name, opts, command, option, domain collide with names of properties on the commander instance. See issues: #404, #584, #648

Important: safe-commander solves the name collision problem, however using it requires changing your code.

Installation

$ npm install safe-commander --save

Usage

Follow Commander API documentation

Breaking changes

Options created with option API will no longer be available on the Commander instance object. Instead, a new object store optsObj was added.

The original Commander.js example should be modified as follows:

 #!/usr/bin/env node

 /**
  * Module dependencies.
  */

-var program = require('commander');
+var program = require('safe-commander');

 program
   .version('0.1.0')
   .option('-p, --peppers', 'Add peppers')
   .option('-P, --pineapple', 'Add pineapple')
   .option('-b, --bbq-sauce', 'Add bbq sauce')
   .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
   .parse(process.argv);

 console.log('you ordered a pizza with:');
-if (program.peppers) console.log('  - peppers');
-if (program.pineapple) console.log('  - pineapple');
-if (program.bbqSauce) console.log('  - bbq');
-console.log('  - %s cheese', program.cheese);
+if (program.optsObj.peppers) console.log('  - peppers');
+if (program.optsObj.pineapple) console.log('  - pineapple');
+if (program.optsObj.bbqSauce) console.log('  - bbq');
+console.log('  - %s cheese', program.optsObj.cheese);

Credits

author

contributors

Contributing

  • Improve the documentation
  • Feel free to open any PR

License

MIT