2.0.7 • Published 4 years ago
cmd-args v2.0.7
cmd-args
A simple command-line argument parser for NodeJS command-line tools.
Install:
$ npm install cmd-args
example:
import { createArgParser } from 'cmd-args'
const myParser = createArgParser({
cmd: 'my-cmd',
title: 'My CMD',
description: 'my-cmd description...',
help: true,
version: 'v1.0.0',
run: (options) => {
console.log(options)
},
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,
},
],
})
myParser.run()
example run:
$ my-cmd --version
outputs:
v1.0.0
example run:
$ my-cmd --help
outputs:
My CMD
my-cmd description...
Usage:
my-cmd [OPTIONS] --help
OR
my-cmd [OPTIONS] <input-files>...
my-cmd [OPTIONS]:
--version Prints version of this command.
--help Prints help text for this command.
-v, --verbose Enable verbose mode.
-o, --output-file[=ARG] Specifies location to write the output file. If not set the output will go to stdout.
ARGUMENTS:
input-files=ARG+ List of input files to be used.
example run:
$ my-cmd file1 file2
outputs:
{
"verbose": false,
"input-files": ["file1", "file2"]
}
example run:
$ my-cmd file1 file2 -o file-out
outputs:
{
"verbose": false,
"input-files": ["file1", "file2"],
"output-file": "file-out"
}
example run:
$ my-cmd file1 file2 --output-file file-out
outputs:
{
"verbose": false,
"input-files": ["file1", "file2"],
"output-file": "file-out"
}
example run:
$ my-cmd -v file1 file2 --output-file file-out
outputs:
{
"verbose": true,
"input-files": ["file1", "file2"],
"output-file": "file-out"
}
2.0.7
4 years ago
2.0.6
4 years ago
2.0.5
4 years ago
2.0.4
4 years ago
2.0.3
4 years ago
2.0.2
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
2.0.0-alpha-3
4 years ago
2.0.0-alpha-2
4 years ago
2.0.0-alpha
4 years ago
1.0.0
8 years ago
0.1.0
8 years ago
0.0.2
8 years ago
0.0.1
8 years ago