commander.js-error
v1.1.0
Published
A tiny module for formatting error output to match commander.js default errors
Downloads
43
Maintainers
Readme
commander.js-error
A tiny module for formatting error output to match commander.js default errors.
Intended to be used in conjunction with commander.js.
Does just what it says; nothing more, nothing less.
Instead of this:
$ node script.js
unknown [foo]: foo must be of type bar
$ <prompt>
you get this:
$ node script.js
error: unknown [foo]: foo must be of type bar
$ <prompt>
That is all.
Installation
$ npm install --save commander.js-error
Usage
const error = require('commander.js-error');
error(new Error('unknown [foo]: foo must be of type bar'));
Follows the same syntax as console.error:
const foo = 'bar';
error('unknown [foo]:', 'foo must be of type', foo);
Options
commander.js-error
accepts options, but they must be at the first position in the arguments list, i.e.:
const error = require('commander.js-error');
error(options, message1, ...); // WILL work
error(options, new Error('oops!')); // WILL work
error(message1, ..., options); // WILL NOT work
error(new Error('oops!'), options); // WILL NOT work
options
should be an object and can contain any of the following:
exit
{mixed} - Whether or not to exit. Possible values:false
- do not exittrue
- exit with a status of1
(default)[0...255]
- exit with a status ofexit
verbose
{boolean} - Log the fullstack trace
(if anError
object is supplied) andexit status
.
Contributing
License
The MIT License (MIT)
Copyright (c) 2016 Justin Helmer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.