Skip to content

[NPM Package] ARGV : A simple and lightweight module to parse command line arguments

Notifications You must be signed in to change notification settings

Cafeine-Software/argv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Argv.js

Node Npm

Tests

A simple and lightweight module to parse command line arguments

InstallationUsageLicenseContact


Installation

Install the package via npm:

npm i @cafeine-software/argv

Usage

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.

About

[NPM Package] ARGV : A simple and lightweight module to parse command line arguments

Topics

Resources

Stars

Watchers

Forks