1.0.0-alpha.1.0.1 • Published 6 years ago
command-handling v1.0.0-alpha.1.0.1
command-handling
The lightweight Node.js command handling that is using for CLI app. This package is also using for code-template-generator.
You can view Commander.js if you are thinking about a great Node.js CLI app. This package is using for small app that is not has many complex features.
Table of contents
- Syntax
- Methods
- Data structures
- Examples
- Thank you!
Syntax
$ command [option] [sub-option] [argument]
Methods
Method | Argument | Description |
---|---|---|
.option() | <flag>, [alias], [description] | Option definition |
.subOption() | <mainFlag>, <subFlag>, description | Sub option definition |
.showOptions() | - | It returns an options array |
.parse() | <process.argv> | Parse the command line |
Data structures
An object is returned when you call method .parse(process.argv)
. View examples for more detail.
{ mainFlag: null,
subFlags: [],
argument: null,
commandLength: 0,
unknowns: [] }
An array is returned when you call method .showOptions()
[
{
flag: '', // main flag
alias: '',
description: '',
subFlags: [{
flag: '', // sub flag
description: ''
}]
},
{
...
}
]
Examples
const { Command } = require('command-handling');
const command = new Command();
command
.option("-v", "--version", "View the installed version")
.option("-help", "--help", "View the help information")
.option("-cf", "--config", "Config for this app")
.subOption("-cf", "--set-asset", "Store the asset directory path")
.subOption("-cf", "--view-asset", "View the asset directory path")
.parse(process.argv);
const options = command.showOptions();
console.log(options); // It returns an object array with all options
View /example.js
file for more details.
Thank you!
Many thanks to Commander.js for the inspiration.
(Completed document is comming soon)
1.0.6
6 years ago
1.0.5
6 years ago
1.0.5-alpha.1.0.1
6 years ago
1.0.5-alpha.1.0.0
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago
1.0.0-alpha.1.0.4
6 years ago
1.0.0-alpha.1.0.3
6 years ago
1.0.0-alpha.1.0.2
6 years ago
1.0.0-alpha.1.0.1
6 years ago
1.0.0-alpha.1.0.0
6 years ago