getflags
Parses arguments into long and short flags, with or without value.
Install
npm install --save getflags
Usage
The module exports a function that takes as arguments the argv
array (splice
from 2 to only include the program arguments), and a
configuration of recognized flags. When a false flag is detected (not
recognized or given a value when not expected and vice versa) an
exception is thrown. Example:
const process = ;const getflags = ; console;
Saving that into example.js
and running with:
node example.js --some 1 \ --collector first \ --better=some-text \ --a -c='second collector' \ --
returns:
some: '1' collector: 'first' 'second collector' better: 'some-text' and: true function: true g: 'and some with space' d: 'when not specified'