args
Advanced tools
Comparing version 2.4.2 to 2.5.0
37
index.js
@@ -12,2 +12,3 @@ 'use strict'; | ||
const chalk = require('chalk'); | ||
const stringSimilarity = require('string-similarity'); | ||
@@ -40,3 +41,3 @@ class Args { | ||
if (typeof usage !== 'string' || typeof description !== 'string') { | ||
throw new Error( | ||
throw new TypeError( | ||
'Usage for adding an Example: args.example("usage", "description")' | ||
@@ -420,7 +421,7 @@ ); | ||
// proxy SIGINT to child process | ||
// Proxy SIGINT to child process | ||
process.on('SIGINT', () => { | ||
if (this.child) { | ||
this.child.kill('SIGINT'); | ||
this.child.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die | ||
this.child.kill('SIGTERM'); // If that didn't work, we're probably in an infinite loop, so make it die | ||
} | ||
@@ -484,3 +485,4 @@ }); | ||
} | ||
// chain all colors to our print method | ||
// Chain all colors to our print method | ||
this.printMainColor = this.printMainColor[this.config.mainColor[item]]; | ||
@@ -497,3 +499,4 @@ } | ||
} | ||
// chain all colors to our print method | ||
// Chain all colors to our print method | ||
this.printSubColor = this.printSubColor[this.config.subColor[item]]; | ||
@@ -526,2 +529,3 @@ } | ||
const optionList = this.getOptions(); | ||
const unknownSubcommand = !defined && subCommand; | ||
@@ -540,5 +544,21 @@ Object.assign(args, this.raw); | ||
if (unknownSubcommand) { | ||
const availableSubcommands = this.details.commands.map(sub => sub.usage); | ||
const suggestSubcommand = stringSimilarity.findBestMatch( | ||
subCommand, | ||
availableSubcommands | ||
); | ||
console.log(`\nUnknown Subcommand ${this.printMainColor(subCommand)}`); | ||
if (suggestSubcommand.bestMatch.rating >= 0.5) { | ||
// 0.5 rating will catch small typos, e.g. import => omport | ||
console.log( | ||
`Did you mean ${this.printMainColor(suggestSubcommand.bestMatch.target)}?` | ||
); | ||
} | ||
} | ||
// Show usage information if "help" or "h" option was used | ||
// And respect the option related to it | ||
if (this.config.help && helpTriggered) { | ||
if ((this.config.help && helpTriggered) || unknownSubcommand) { | ||
this.showHelp(); | ||
@@ -624,2 +644,5 @@ } | ||
module.exports = (exports.default = new Args()); | ||
const instance = new Args(); | ||
module.exports = instance; | ||
exports.default = instance; |
{ | ||
"name": "args", | ||
"version": "2.4.2", | ||
"version": "2.5.0", | ||
"description": "Minimal toolkit for building CLIs", | ||
@@ -43,16 +43,17 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "0.18.2", | ||
"eslint-config-prettier": "1.5.0", | ||
"execa": "0.6.0", | ||
"ava": "0.19.1", | ||
"eslint-config-prettier": "1.6.0", | ||
"execa": "0.6.3", | ||
"husky": "0.13.3", | ||
"lint-staged": "3.4.0", | ||
"prettier": "0.22.0", | ||
"xo": "0.17.0" | ||
"xo": "0.18.1" | ||
}, | ||
"dependencies": { | ||
"camelcase": "4.0.0", | ||
"camelcase": "4.1.0", | ||
"chalk": "1.1.3", | ||
"minimist": "1.2.0", | ||
"pkginfo": "0.4.0" | ||
"pkginfo": "0.4.0", | ||
"string-similarity": "1.1.0" | ||
} | ||
} |
27834
517
5
+ Addedstring-similarity@1.1.0
+ Addedcamelcase@4.1.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedstring-similarity@1.1.0(transitive)
- Removedcamelcase@4.0.0(transitive)
Updatedcamelcase@4.1.0