This is a configuration loader based on rc,
extended by argument validation and --help
.
const { Vrc } = require( 'vrc' );
const conf = new Vrc( 'myAppName', [
{ name: 'name', dflt: 'Jack', desc: 'Name to print', type: 'string' },
], { description: 'This tool solves any problem given' } ).run();
console.log( `Name: ${conf.get('name')}` );
Automatic help shows default values and actually used values.
vrc( appName, conf ) : { conf, invalidNames }
Returns the conf object from rc
and a list of invalid names where the user supplied wrong parameters
(e.g. string instead of number). Invalid values will be replaced by their defaults.
A configuration entry takes the following arguments:
-
name
: Name of the variable/parameter -
desc
: Description, shown in the help -
dflt
: Default value -
type
: Supported values:'string'
,'number'
,'boolean'
,number[]
,number[][]
-
options
: Array holding valid options for the argument. Currently only for strings.
Number arrays are passed as comma-separated values and are converted; 1,3,42
results in [1,3,42]
.
Vrc can be used with limited typing support by passing an interface to the constructor.
import { Vrc } from 'vrc';
interface Conf {
balloons : number;
colour : string;
}
const conf = new Vrc<Conf>( 'balloon', [
{ name: 'balloons', type: 'number', dflt: 99, desc: 'Number of balloons' },
{ name: 'colour', type: 'string', dflt: 'red', desc: 'Balloon colour' },
] ).run();
console.log( conf.conf.balloons ); // 99
- Update dependencies
-
Added:
VrcSettings
accept anadditionalHelp
callback function which, if defined, can print additional help text which is shown on--help
.const conf = new VrcConf( 'foo', [], { additionalHelp: () => 'More details' } );
-
Changed:
braces
dependency updated
- Breaking: Constructor throws an error if an argument starts with
no-
because this is used as a prefix for negated boolean arguments byrc
. (If this causes issues, please open an issue on GitHub.)
- Update dependencies
- Update dependencies
- Update dependencies
- Revert TypeScript changes from 2.4.0
- Update dependencies
- Add support for options to number type parameter
- Default arguments are validated against options
- Convert Numbers to string for string parameters
- Update dependencies and correct changelog
- Changed help output to redact user-provided secrets
- Update minimist dependency to fix audit issue
This version fixes the way arguments are marked as invalid and does not replace invalid user arguments by default values anymore as this is potentially dangerous.
- Added
VrcConf.unnamedArgs
which contains positional/unnamed arguments - Added
VrcConf.printArgs()
to print a summary of all arguments - Added the
secr
modifier for arguments which causes them not to be printed with the above function - Breaking: Invalid arguments are not replaced by default values anymore.
- Breaking: Configuration is now created with
new Vrc()
which can be typed in TypeScript. - Breaking: To evaluate the help parameter, use
new Vrc().run()
. - Removed:
VrcConf.invalidNames
- Added:
vrc
now returns aVrcConf
object which can e.g. check if an argument is using a default value or a user-provided value. The object is backwards compatible and still exhibits the old properties.
- Added
options
for string parameters to define possible values
- Changed: Long description lines are now wrapped in the help output.
- Added support for
string[]