Comparing version 1.0.0 to 2.0.0-alpha
{ | ||
"name": "cmd-args", | ||
"version": "1.0.0", | ||
"version": "2.0.0-alpha", | ||
"description": "A simple command-line argument parser for NodeJS command-line tools.", | ||
"main": "index.js", | ||
"main": "dist/cmd-args.js", | ||
"scripts": { | ||
@@ -27,5 +27,11 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
"homepage": "https://github.com/Mike96Angelo/cmd-args#readme", | ||
"dependencies": { | ||
"generate-js": "^3.0.0" | ||
"devDependencies": { | ||
"@types/jest": "^26.0.9", | ||
"jest": "^26.3.0", | ||
"ts-jest": "^26.1.4", | ||
"tslint": "^6.1.3", | ||
"tslint-config-airbnb": "^5.11.2", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.9.7" | ||
} | ||
} |
223
README.md
@@ -1,5 +0,12 @@ | ||
# cmd-args v1.0.0 | ||
# cmd-args | ||
[](https://github.com/Mike96Angelo/cmd-args) | ||
[](https://www.npmjs.com/package/cmd-args) | ||
[](https://www.npmjs.com/package/cmd-args) | ||
[](https://www.npmjs.com/package/cmd-args) | ||
A simple command-line argument parser for NodeJS command-line tools. | ||
Install: | ||
``` | ||
@@ -9,161 +16,113 @@ $ npm install cmd-args | ||
example (my-program.js): | ||
example: | ||
```javascript | ||
var CommandLineParser = require('cmd-args'); | ||
```typescript | ||
import { createArgParser } from 'cmd-args' | ||
var cmdArgs = new CommandLineParser([ | ||
// [<alias>, <flag>, <description>] | ||
['h', 'help', 'Displays the help for this program.'], | ||
['f', 'firstname=ARG', 'Required firstname arg.' ], | ||
['l', 'lastname[=ARG]', 'Optional lastname arg.' ], | ||
['m', 'middlename[=ARG+]', 'Optional multiple middlename args.' ], | ||
['v', 'verbose', 'Verbose boolean flag.' ], | ||
[null, 'quite', 'Quite boolean flag no alias.' ], | ||
]); | ||
const myParser = createArgParser({ | ||
cmd: 'my-cmd', | ||
title: 'My CMD', | ||
description: 'my-cmd description...', | ||
options: [ | ||
{ | ||
type: 'flag', | ||
key: 'verbose', | ||
alias: 'V', | ||
description: 'Enable verbose mode.' | ||
}, | ||
{ | ||
type: 'option', | ||
key: 'output-file', | ||
alias: 'o', | ||
description: 'Specifies location to write the output file. If not set the output will go to stdout.' | ||
} | ||
], | ||
arguments: [ | ||
{ | ||
key: 'input-files', | ||
description: 'List of input files to be used.' | ||
multi: true, | ||
required: true | ||
} | ||
] | ||
}); | ||
var CMD_ARGS = cmdArgs.parse(process.argv.slice(2)); | ||
var program = myParser.parse(process.argv.slice(2)); | ||
if (CMD_ARGS.options.help) { // show help and exit | ||
console.log('\nUsage: my-program <flags>'); | ||
console.log('\nFlags:'); | ||
console.log(cmdArgs.help()); | ||
process.exit(0); | ||
} | ||
console.log(CMD_ARGS); | ||
console.log(JSON.stringify(program), null, 2)) | ||
``` | ||
Terminal: | ||
example run: | ||
```bash | ||
$ my-cmd file1 file2 | ||
``` | ||
$ node my-program --help | ||
Usage: my-program <flags> <argv> | ||
outputs: | ||
Flags: | ||
-h, --help Displays the help for this program. | ||
-f, --firstname=ARG Required firstname arg. | ||
-l, --lastname[=ARG] Optional lastname arg. | ||
-m, --middlename[=ARG+] Optional multiple middlename args. | ||
-v, --verbose Verbose boolean flag. | ||
--quite Quite boolean flag no alias. | ||
$ node my-program | ||
```json | ||
{ | ||
argv: [], | ||
options: {}, | ||
error: [Error: Missing required option: -f, --firstname] | ||
"cmd": "my-cmd", | ||
"options": { | ||
"verbose": false, | ||
"input-files": ["file1", "file2"] | ||
} | ||
} | ||
``` | ||
$ node my-program --firstname | ||
{ | ||
argv: [], | ||
options: {}, | ||
error: [Error: Invalid value supplied: -f, --firstname] | ||
} | ||
example run: | ||
$ node my-program --firstname John | ||
{ | ||
argv: [], | ||
options: { | ||
firstname: 'John' | ||
}, | ||
error: null | ||
} | ||
```bash | ||
$ my-cmd file1 file2 -o file-out | ||
``` | ||
$ node my-program -f John | ||
{ | ||
argv: [], | ||
options: { | ||
firstname: 'John' | ||
}, | ||
error: null | ||
} | ||
outputs: | ||
$ node my-program test -f John | ||
```json | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John' | ||
}, | ||
error: null | ||
"cmd": "my-cmd", | ||
"options": { | ||
"verbose": false, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
} | ||
``` | ||
$ node my-program test -f John -m Jim | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John', | ||
middlename: ['Jim'] | ||
}, | ||
error: null | ||
} | ||
example run: | ||
$ node my-program test -f John -m Jim -m Joe | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John', | ||
middlename: ['Jim', 'Joe'] | ||
}, | ||
error: null | ||
} | ||
```bash | ||
$ my-cmd file1 file2 --output-file file-out | ||
``` | ||
$ node my-program test -f John -m Jim -m Joe -l Doe | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John', | ||
middlename: ['John', 'Jim'], | ||
lastname: 'Doe' | ||
}, | ||
error: null | ||
} | ||
outputs: | ||
$ node my-program test -f John -m Jim -m Joe -l Doe -l Bob | ||
```json | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John', | ||
middlename: ['John', 'Jim'], | ||
lastname: 'Doe' | ||
}, | ||
error: [Error: Flag already set: -l, --lastname] | ||
"cmd": "my-cmd", | ||
"options": { | ||
"verbose": false, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
} | ||
``` | ||
$ node my-program test -fmml John Jim Joe Doe | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John', | ||
middlename: ['John', 'Jim'], | ||
lastname: 'Doe' | ||
}, | ||
error: null | ||
} | ||
example run: | ||
$ node my-program test -vfmml John Jim Joe Doe | ||
{ | ||
argv: ['test'], | ||
options: { | ||
verbose: true, | ||
firstname: 'John', | ||
middlename: ['John', 'Jim'], | ||
lastname: 'Doe' | ||
}, | ||
error: null | ||
} | ||
```bash | ||
$ my-cmd -v file1 file2 --output-file file-out | ||
``` | ||
$ node my-program test -fmml John Jim Joe Doe --quite | ||
outputs: | ||
```json | ||
{ | ||
argv: ['test'], | ||
options: { | ||
firstname: 'John', | ||
middlename: ['John', 'Jim'], | ||
lastname: 'Doe', | ||
quite: true | ||
}, | ||
error: null | ||
"cmd": "my-cmd", | ||
"options": { | ||
"verbose": true, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
41941
0
11
828
7
2
128
1
- Removedgenerate-js@^3.0.0
- Removedgenerate-js@3.1.2(transitive)