@cafeine-software/argv
v1.1.1
Published
A simple and lightweight module to parse command line arguments
Downloads
16
Maintainers
Readme
Argv.js
A simple and lightweight module to parse command line arguments
Installation • Usage • License • Contact
Installation
Install the package via npm:
npm i @cafeine-software/argvUsage
Importing
import Argv from '@cafeine-software/argv';Parse Example
If you run the following script:
node script.js --verbose -f config.json --debug --foo=bar --toto="true"The code:
const args = Argv.parse();
console.log(args);Will output:
{
verbose: true,
f: 'config.json',
debug: true
foo:"var",
toto:true
}Check Mandatory Args
Use Argv.hasMandatoryArgs() to ensure required options are present before running your logic:
import Argv from '@cafeine-software/argv';
if (!Argv.hasMandatoryArgs(['config', 'verbose'])) {
console.error('Missing required arguments: --config and --verbose');
process.exit(1);
}
hasMandatoryArgs returns true only if every key you list exists in the parsed arguments object.
License
Contact
Developed by Quentin Lamamy.
- Email: [email protected]
- GitHub: github.com/quentin-lamamy
- Cafeine Github: github.com/Cafeine-Software
