What is the Consultant?
Consultant is an JavaScript library which allows us getting parameters (or options) from various sources such as command line, string or interactive menu.
Provides:
- Well-defined input model for operations require parameters.
- Declerative approach.
- Multiple methods for getting parameter (or options)
- Parsing command line input like
cmd --parameter=value --option1 --option2
. - Interactive command line user interface to getting options directly from user.
- Prepares an help output based on model definition.
Example Usage
import consultant from 'consultant';
const rules = {
main: {
rules: {
makefile: {
type: String,
aliases: [ 'f' ],
label: 'Makefile',
description: 'Load tasks from FILE',
parameter: 'FILE',
'default': [ 'makefile.js' ],
uiHidden: false,
min: 0,
max: undefined,
validate: function (value) {
return value.length >= 3 || 'minimum 3 chars required';
}
},
tasks: {
type: Boolean,
aliases: [ 't' ],
label: 'Tasks',
description: 'Lists defined tasks',
'default': false,
uiHidden: true,
min: 0,
max: 1
},
verbosity: {
type: String,
label: 'Verbosity',
description: 'Sets verbosity of log messages [debug, warn, info, error]',
'default': 'info',
values: [ 'debug', 'warn', 'info', 'error' ],
uiHidden: true,
min: 0,
max: 1
},
version: {
type: Boolean,
aliases: [ 'v' ],
label: 'Version',
description: 'Displays the jsmake version',
'default': false,
uiHidden: true,
min: 0,
max: 1
},
help: {
type: Boolean,
aliases: [ 'h', '?' ],
label: 'Help',
description: 'Displays this help message',
'default': false,
uiHidden: true,
min: 0,
max: 1
}
}
}
};
const ruleCollection = consultant.createRuleCollection(rules);
const argv = consultant.parse(process.argv.slice(2));
console.log(ruleCollection.validate('main', argv));
ruleCollection.inquiry('main')
.then((answers) => {
console.log(answers);
});
const help = [];
ruleCollection.help('main', help);
console.log(help);
Quick start
Execute npm install consultant --save
to install consultant and its dependencies into your project directory.
Todo List
See GitHub Projects for more.
Requirements
License
Apache 2.0, for further details, please see LICENSE file
Contributing
See contributors.md
It is publicly open for any contribution. Bugfixes, new features and extra modules are welcome.
- To contribute to code: Fork the repo, push your changes to your fork, and submit a pull request.
- To report a bug: If something does not work, please report it using GitHub Issues.
To Support
Visit my patreon profile at patreon.com/eserozvataf