minimal-cli
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -55,2 +55,4 @@ 'use strict'; | ||
this.aliasFlags(flags, this.options); | ||
if (args.help) { | ||
@@ -95,7 +97,33 @@ this.outputHelp(); | ||
const [name, type, description] = flag; | ||
const { alias, id } = this.parseFlag(name); | ||
return { name, type, description }; | ||
return { name, alias, id, type, description }; | ||
}); | ||
} | ||
parseFlag(flag) { | ||
const aliasMatch = flag.match(/(?:^|[^-])-(\w+)/i); | ||
const idMatch = flag.match(/--(\w+)/i); | ||
const alias = aliasMatch !== null ? aliasMatch[1] : null; | ||
const id = idMatch !== null ? idMatch[1] : null; | ||
return { alias, id }; | ||
} | ||
aliasFlags(flags, options) { | ||
options.flags.filter(flag => flag.id).forEach(flag => { | ||
const { id, alias } = flag; | ||
if (alias) { | ||
if (flags[alias]) { | ||
flags[id] = flags[alias]; | ||
} | ||
if (flags[id]) { | ||
flags[alias] = flags[id]; | ||
} | ||
} | ||
}); | ||
} | ||
outputHelp() { | ||
@@ -102,0 +130,0 @@ process.stdout.write(this.helpText); |
{ | ||
"name": "minimal-cli", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "A simple package for creating minimal command-line programs", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"dependencies": { | ||
"minimal-cli-parser": "0.0.1" | ||
"minimal-cli-parser": "0.1.0" | ||
}, | ||
@@ -48,5 +48,5 @@ "devDependencies": { | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"nyc": "^14.1.1", | ||
"standard": "^12.0.1" | ||
} | ||
} |
@@ -8,4 +8,2 @@ # minimal-cli | ||
[![Coverage](https://img.shields.io/codecov/c/github/JoshCrozier/minimal-cli.svg?style=flat-square)](https://codecov.io/github/JoshCrozier/minimal-cli) | ||
[![Dependencies](https://img.shields.io/david/JoshCrozier/minimal-cli.svg?style=flat-square)](https://david-dm.org/JoshCrozier/minimal-cli) | ||
[![DevDependencies](https://david-dm.org/JoshCrozier/minimal-cli/dev-status.svg?style=flat-square)](https://david-dm.org/JoshCrozier/minimal-cli?type=dev) | ||
[![Vulnerabilities](https://snyk.io/test/npm/minimal-cli/badge.svg?style=flat-square)](https://snyk.io/test/npm/minimal-cli) | ||
@@ -49,3 +47,5 @@ | ||
"url": "https://example.com", | ||
"verbose": true | ||
"verbose": true, | ||
"u": "https://example.com", // handles the aliasing | ||
"v": true // handles the aliasing | ||
} | ||
@@ -52,0 +52,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8890
6
108
+ Addedminimal-cli-parser@0.1.0(transitive)
- Removedminimal-cli-parser@0.0.1(transitive)
Updatedminimal-cli-parser@0.1.0