Initial commit
This commit is contained in:
4
node_modules/cliss/.jshintrc
generated
vendored
Normal file
4
node_modules/cliss/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"esversion": 6,
|
||||
"node": true
|
||||
}
|
||||
5
node_modules/cliss/.travis.yml
generated
vendored
Normal file
5
node_modules/cliss/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 6
|
||||
- 8
|
||||
- 9
|
||||
508
node_modules/cliss/README.md
generated
vendored
Normal file
508
node_modules/cliss/README.md
generated
vendored
Normal file
@@ -0,0 +1,508 @@
|
||||
# CLIss
|
||||
|
||||
[](https://travis-ci.org/DiegoZoracKy/cliss) []() []()
|
||||
|
||||
CLI Simple, Stupid. Automatic discovery of parameters names and support to subcommands down to N levels. Provides an easy and minimal setup by passing in only a function reference without the need of declaring all expected options names or create a help section by hand.
|
||||
|
||||
## Goals
|
||||
|
||||
* Simple and easy API
|
||||
* Easy minimal setup, extracting options names from functions parameters
|
||||
* Out of the box support to sync or async (Promise) functions
|
||||
* Subcommands down to N levels
|
||||
* Automatic Help section generation, that can be improved only when needed
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install cliss
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Through this section we'll be going from the most minimal usage of the module, where options names are extracted from functions parameters:
|
||||
```javascript
|
||||
const func = (param1, param2) => `${param1}_${param2}`;
|
||||
cliss(func);
|
||||
```
|
||||
|
||||
to a version using all the possible options it provides:
|
||||
|
||||
```javascript
|
||||
const cliSpec = {
|
||||
name,
|
||||
description,
|
||||
version,
|
||||
options: [{
|
||||
name,
|
||||
description,
|
||||
required,
|
||||
type
|
||||
}],
|
||||
pipe: {
|
||||
stdin: (stdinValue, args, positionalArgs, argsAfterEndOfOptions) => {},
|
||||
before: (args, positionalArgs, argsAfterEndOfOptions) => {},
|
||||
after: (result, parsedArgs, positionalArgs, argsAfterEndOfOptions) => {}
|
||||
},
|
||||
action: () => {},
|
||||
commands: [{}]
|
||||
};
|
||||
|
||||
const clissOptions = {
|
||||
command: {
|
||||
subcommandsDelimiter
|
||||
},
|
||||
options: {
|
||||
validateRequiredParameters
|
||||
},
|
||||
version: {
|
||||
option
|
||||
},
|
||||
help: {
|
||||
option,
|
||||
stripAnsi
|
||||
},
|
||||
pipe: {
|
||||
stdin: (stdinValue, args, positionalArgs, argsAfterEndOfOptions) => {},
|
||||
before: (args, positionalArgs, argsAfterEndOfOptions) => {},
|
||||
after: (result, parsedArgs, positionalArgs, argsAfterEndOfOptions) => {}
|
||||
}
|
||||
};
|
||||
|
||||
cliss(cliSpec, clissOptions);
|
||||
```
|
||||
|
||||
### A CLI for a function (the most simple and minimal use case)
|
||||
`cliss(functionReference)`
|
||||
|
||||
Creating a CLI for a function by doing nothing more than passing it as a parameter to cliss. The options names will be the same as the parameters expected by the function.
|
||||
|
||||
```javascript
|
||||
'use strict';
|
||||
const cliss = require('cliss');
|
||||
|
||||
const aFunctionWithWeirdParametersDefinition = (param1, param2, { someProp: [[ param3 ]] = [[]] } = {}, ...args) => {
|
||||
let result = `param1: ${param1} \n`;
|
||||
result += `param2: ${param2} \n`;
|
||||
result += `param3: ${param3} \n`;
|
||||
result += `args: ${args.join(',')}`;
|
||||
|
||||
return result;Run the program passing with the following options:
|
||||
|
||||
|
||||
};
|
||||
|
||||
cliss(aFunctionWithWeirdParametersDefinition);
|
||||
```
|
||||
Calling it via CLI with `--help` will give you:
|
||||
|
||||
```bash
|
||||
Options:
|
||||
|
||||
--param1
|
||||
--param2
|
||||
--param3
|
||||
--args
|
||||
```
|
||||
|
||||
Passing in the options:
|
||||
`node cli.js --param2=PARAM2 --param1=PARAM1 --param3=PARAM3 --args=a --args=r --args=g --args=s`
|
||||
|
||||
Or passing options + arguments (arguments for the "...args" parameter in this case):
|
||||
`node cli.js --param2=PARAM2 --param1=PARAM1 --param3=PARAM3 a r g s`
|
||||
|
||||
Will result in:
|
||||
|
||||
```bash
|
||||
param1: PARAM1
|
||||
param2: PARAM2
|
||||
param3: PARAM3
|
||||
args: a,r,g,s
|
||||
```
|
||||
Note that the order of the options doesn't need to match the order of the parameters.
|
||||
|
||||
### Improving the help section
|
||||
`cliss(cliSpec)`
|
||||
|
||||
Great, but probably one would like to improve a bit the `--help` section of the module, by providing to the end user the **name** (the command's name for calling it via CLI), **description** and **version** of the module. In this case a *Object Literal* will be used instead of just a function reference.
|
||||
|
||||
```javascript
|
||||
'use strict';
|
||||
const cliss = require('../');
|
||||
|
||||
cliss({
|
||||
name: 'some-command',
|
||||
description: 'Just an example that will do nothing but concat all the parameters.',
|
||||
version: '1.0.0',
|
||||
action: (param1, param2, { someProp: [[ param3 ]] = [[]] } = {}, ...args) => {
|
||||
let result = `param1: ${param1} \n`;
|
||||
result += `param2: ${param2} \n`;
|
||||
result += `param3: ${param3} \n`;
|
||||
result += `args: ${args.join(',')}`;
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Now, when calling it with `--help`, a better help section will be shown:
|
||||
|
||||
```bash
|
||||
Description:
|
||||
|
||||
Just an example that will do nothing but concat all the parameters.
|
||||
|
||||
Usage:
|
||||
|
||||
$ some-command [options] [args...]
|
||||
|
||||
Options:
|
||||
|
||||
--param1
|
||||
--param2
|
||||
--param3
|
||||
--args
|
||||
```
|
||||
|
||||
### Providing more information about the expected options
|
||||
`cliss(cliSpec)`
|
||||
|
||||
The options were effortlessly extracted from the parameters names, but **cliss** provides a way for one to provide more information about each of them. The *Object Literal* passed in the *cliSpec* parameter can have a property named **options**, which expects an *Array* of objects, containing the **name** of the option plus some of the following properties:
|
||||
|
||||
* **required**
|
||||
To tell if the parameter is required.
|
||||
|
||||
* **description**
|
||||
To give hints or explain what the option is about.
|
||||
|
||||
* **type**
|
||||
To define how the parser should treat the option (Array, Object, String, Number, etc.). Check [yargs-parser](https://github.com/yargs/yargs-parser) for instructions about *type*, as it is the engine being used to parse the options.
|
||||
|
||||
* **alias**
|
||||
To define an alias for the option.
|
||||
|
||||
Following the last example, let's improve it to:
|
||||
* give more information about **param1**
|
||||
* check **args** as required
|
||||
|
||||
```javascript
|
||||
cliss({
|
||||
name: 'some-command',
|
||||
description: 'Just an example that will do nothing but concat all the parameters.',
|
||||
version: '1.0.0',
|
||||
options: [{
|
||||
name: 'param1',
|
||||
description: 'This param is the base value to compute everything else.',
|
||||
required: true,
|
||||
type: 'String'
|
||||
}, {
|
||||
name: 'args',
|
||||
required: true
|
||||
}],
|
||||
action: (param1, param2, { someProp: [[ param3 ]] = [[]] } = {}, ...args) => {
|
||||
let result = `param1: ${param1} \n`;
|
||||
result += `param2: ${param2} \n`;
|
||||
result += `param3: ${param3} \n`;
|
||||
result += `args: ${args.join(',')}`;
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Call `--help`, and note that the *Usage* section will also be affected. Now *[options] [args...]* will be shown as *<options> <args...>*, because both of them are required.
|
||||
|
||||
```bash
|
||||
Description:
|
||||
|
||||
Just an example that will do nothing but logging all the parameters.
|
||||
|
||||
Usage:
|
||||
|
||||
$ some-command <options> <args...>
|
||||
|
||||
Options:
|
||||
|
||||
--param1 String Required - This param is the base value to compute
|
||||
everything else.
|
||||
--param2
|
||||
--param3
|
||||
--args Required
|
||||
```
|
||||
|
||||
Run the program with the following options:
|
||||
`node cli.js --param1=001 --param2=002 --param3=PARAM3 a r g s`
|
||||
|
||||
And check the result to see how *param1* was indeed treated as a string, while *param2* was parsed as a number:
|
||||
|
||||
```bash
|
||||
param1: 001
|
||||
param2: 2
|
||||
param3: PARAM3
|
||||
args: a,r,g,s
|
||||
```
|
||||
|
||||
### Pipe: STDIN, Before and After
|
||||
`cliss(cliSpec)`
|
||||
|
||||
A property named **pipe** can also be defined on *cliSpec* in order to handle **stdin** and also, some steps of the execution flow (**before** and **after**). To define a single handle for all the commands, the **pipe** option can be defined on [Cliss options](#cliss-options) as will be shown later on the documentation. The pipeline execution of a command is:
|
||||
|
||||
**stdin** *(command.pipe.stdin || clissOptions.pipe.stdin)* =>
|
||||
=> **clissOptions.pipe.before** =>
|
||||
=> **command.pipe.before** =>
|
||||
=> **command.action** =>
|
||||
=> **command.pipe.after** =>
|
||||
=> **clissOptions.pipe.after**
|
||||
=> **stdout**
|
||||
|
||||
Where each of these steps can be handled if needed.
|
||||
|
||||
The properties expected by **pipe** are:
|
||||
|
||||
* **stdin**
|
||||
`(stdinValue, args, positionalArgs, argsAfterEndOfOptions)`
|
||||
|
||||
* **before**
|
||||
`(args, positionalArgs, argsAfterEndOfOptions)`
|
||||
To transform the data being input, before it is passed in to the main command action.
|
||||
|
||||
* **after**
|
||||
`(result, parsedArgs, positionalArgs, argsAfterEndOfOptions)`
|
||||
To transform the *output* (for example, to JSON.stringify an *Object Literal*)
|
||||
|
||||
Note: **stdin** and **before** must always return *args*, and **after** must always return *result*, as these values will be passed in for the next function in the pipeline.
|
||||
|
||||
To better explain with an example, let's modify the previous one to:
|
||||
|
||||
* get *param3* from **stdin**
|
||||
* use **before** to reverse *...args* array
|
||||
* use **after** to decorate the output
|
||||
|
||||
Check the *pipe* property on the following code:
|
||||
|
||||
```javascript
|
||||
cliss({
|
||||
name: 'some-command',
|
||||
description: 'Just an example that will do nothing but concat all the parameters.',
|
||||
version: '1.0.0',
|
||||
options: [{
|
||||
name: 'param1',
|
||||
description: 'This param is needed to compute everything else.',
|
||||
required: true,
|
||||
type: 'String'
|
||||
}, {
|
||||
name: 'args',
|
||||
required: true
|
||||
}],
|
||||
pipe: {
|
||||
stdin: (stdinValue, args, positionalArgs, argsAfterEndOfOptions) => {
|
||||
args.param3 = stdinValue;
|
||||
return args;
|
||||
},
|
||||
before: (args, positionalArgs, argsAfterEndOfOptions) => {
|
||||
positionalArgs.reverse();
|
||||
return args;
|
||||
},
|
||||
after: (result, parsedArgs, positionalArgs, argsAfterEndOfOptions) => {
|
||||
return `======\n${result}\n======`;
|
||||
}
|
||||
},
|
||||
action: (param1, param2, { someProp: [[ param3 ]] = [[]] } = {}, ...args) => {
|
||||
let result = `param1: ${param1} \n`;
|
||||
result += `param2: ${param2} \n`;
|
||||
result += `param3: ${param3} \n`;
|
||||
result += `args: ${args.join(',')}`;
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Calling it as:
|
||||
`echo "fromSTDIN" | node cli.js --param1=001 --param2=002 a r g s`
|
||||
|
||||
Will result in:
|
||||
|
||||
```bash
|
||||
=======
|
||||
param1: 001
|
||||
param2: 2
|
||||
param3: fromSTDIN
|
||||
args: s,g,r,a
|
||||
=======
|
||||
```
|
||||
|
||||
### Subcommands
|
||||
|
||||
Subcommands can be defined in a very simple way. Thinking naturally, a subcommand should be just a command that comes nested into another one, and it is exactly how it's done.
|
||||
|
||||
Here one more property of the *cliSpec* is introduced: **commands**. It is an *Array* that can contains N commands, including the **commands** property (commands can be nested down to N levels).
|
||||
|
||||
As each subcommand is a command itself, they also counts with its own `--help` section, and possibly its own `--version` (if it is not defined for a subcommand, the one defined for the root will be shown).
|
||||
|
||||
The following example will introduce:
|
||||
|
||||
* 1 subcommand, thas has no action, and contains more 2 subcommands
|
||||
* 1 subcommand that contains an action
|
||||
|
||||
```javascript
|
||||
cliss({
|
||||
name: 'some-command',
|
||||
description: 'Just an example that will do nothing but concat all the parameters.',
|
||||
version: '1.0.0',
|
||||
options: [{
|
||||
name: 'param1',
|
||||
description: 'This param is the base value to compute everything else.',
|
||||
required: true,
|
||||
type: 'String'
|
||||
}, {
|
||||
name: 'args',
|
||||
required: true
|
||||
}],
|
||||
pipe: {
|
||||
stdin: (stdinValue, args, positionalArgs, argsAfterEndOfOptions) => {
|
||||
args.param3 = stdinValue;
|
||||
return args;
|
||||
},
|
||||
before: (args, positionalArgs, argsAfterEndOfOptions) => {
|
||||
positionalArgs.reverse();
|
||||
return args;
|
||||
},
|
||||
after: (result, parsedArgs, positionalArgs, argsAfterEndOfOptions) => {
|
||||
return `======\n${result}\n======`;
|
||||
}
|
||||
},
|
||||
action: (param1, param2, { someProp: [[ param3 ]] = [[]] } = {}, ...args) => {
|
||||
let result = `param1: ${param1} \n`;
|
||||
result += `param2: ${param2} \n`;
|
||||
result += `param3: ${param3} \n`;
|
||||
result += `args: ${args.join(',')}`;
|
||||
|
||||
return result;
|
||||
},
|
||||
commands: [{
|
||||
name: 'subcommand1',
|
||||
commands: [{
|
||||
name: 'action1',
|
||||
options: [{
|
||||
name: 'param',
|
||||
required: true
|
||||
}],
|
||||
action: param => `subcommand1 action1 param: ${param}`
|
||||
}, {
|
||||
name: 'action2',
|
||||
action: () => 'subcommand1 action2'
|
||||
}]
|
||||
}, {
|
||||
name: 'subcommand2',
|
||||
action: () => console.log('subcommand2')
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
Call `--help` to see that a new section *Commands:* is presented:
|
||||
|
||||
```bash
|
||||
Description:
|
||||
|
||||
Just an example that will do nothing but concat all the parameters.
|
||||
|
||||
Usage:
|
||||
|
||||
$ some-command <options> <args...>
|
||||
$ some-command [command]
|
||||
|
||||
Options:
|
||||
|
||||
--param1 String Required - This param is needed to compute
|
||||
everything else.
|
||||
--param2
|
||||
--param3
|
||||
--args Required
|
||||
|
||||
Commands:
|
||||
|
||||
subcommand1
|
||||
subcommand2
|
||||
```
|
||||
|
||||
Each subcomand has its own help section, check:
|
||||
`node cli.js subcommand1 --help`
|
||||
|
||||
```bash
|
||||
Usage:
|
||||
|
||||
$ some-command subcommand1
|
||||
```
|
||||
|
||||
`node cli.js subcommand2 --help`:
|
||||
|
||||
```bash
|
||||
Usage:
|
||||
|
||||
$ some-command subcommand2 <command>
|
||||
|
||||
Commands:
|
||||
|
||||
action1
|
||||
action2
|
||||
```
|
||||
|
||||
Just call the commands names separated by space:
|
||||
`node cli.js subcommand2 action1 --param=VALUE`
|
||||
|
||||
Result:
|
||||
|
||||
```bash
|
||||
subcommand2 action1 param: VALUE
|
||||
```
|
||||
|
||||
### Cliss options
|
||||
`cliss(cliSpec, clissOptions)`
|
||||
|
||||
An `Object Literal` with the following options can be passed in as the second parameter to cliss:
|
||||
|
||||
* **command**
|
||||
|
||||
* **subcommandsDelimiter**
|
||||
To define a delimiter for a subcommand to be used instead of a white space. For example, if `'-'` is passed in, the subcommands should be called as `subcommand1-action1` instead of `subcommand1 action1`.
|
||||
|
||||
* **options**
|
||||
|
||||
* **validateRequiredParameters**
|
||||
If set to `true`, the required parameters will be checked before the command action is called, and the help section will be shown in case a required parameter is missing.
|
||||
|
||||
* **help**
|
||||
* **option**
|
||||
To define a different option name to show the help section. For example, if `'helpsection'` is passed in, `--helpsection` must be used instead of `--help`.
|
||||
|
||||
* **stripAnsi**
|
||||
Set to `true` to strip all ansi escape codes (colors, underline, etc.) and output just a raw text.
|
||||
|
||||
* **version**
|
||||
* **option**
|
||||
To define a different option name to show the version. For example, if `'moduleversion'` is passed in, `--moduleversion` must be used instead of `--version`.
|
||||
|
||||
* **pipe**
|
||||
As it is defined on *cliSpec* for each command, **pipe** can also be defined in *clissOptions* to implement for all commands a unique way to handle **stdin** and also, some steps of the execution flow (**before** and **after**) in case it is needed. The pipeline execution of a command is:
|
||||
**stdin** *(command.pipe.stdin || clissOptions.pipe.stdin)* =>
|
||||
=> **clissOptions.pipe.before** =>
|
||||
=> **command.pipe.before** =>
|
||||
=> **command.action** =>
|
||||
=> **command.pipe.after** =>
|
||||
=> **clissOptions.pipe.after**
|
||||
=> **stdout**
|
||||
The properties expected by **pipe** are:
|
||||
|
||||
* **stdin**
|
||||
`(stdinValue, args, positionalArgs, argsAfterEndOfOptions)`
|
||||
|
||||
* **before**
|
||||
`(args, positionalArgs, argsAfterEndOfOptions)`
|
||||
To transform the data being input, before it is passed in to the main command action.
|
||||
|
||||
* **after**
|
||||
`(result, parsedArgs, positionalArgs, argsAfterEndOfOptions)`
|
||||
To transform the *output* (for example, to JSON.stringify an *Object Literal*)
|
||||
|
||||
Note: **stdin** and **before** must always return *args*, and **after** must always return *result*, as these values will be passed in for the next function in the pipeline.
|
||||
132
node_modules/cliss/lib/cli-help.js
generated
vendored
Normal file
132
node_modules/cliss/lib/cli-help.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
'use strict';
|
||||
|
||||
const commandLineUsage = require('command-line-usage');
|
||||
const stripAnsiFn = require('strip-ansi');
|
||||
|
||||
function getCommandFromPath(commandPath, subcommandsDelimiter) {
|
||||
commandPath = commandPath.filter(command => !!command);
|
||||
if (subcommandsDelimiter) {
|
||||
return commandPath && commandPath.length && `${commandPath.shift()} ${commandPath.join(subcommandsDelimiter)}`;
|
||||
}
|
||||
|
||||
return commandPath && commandPath.length && commandPath.join(' ');
|
||||
}
|
||||
|
||||
function prepareDescriptionSection(description) {
|
||||
return description && { header: 'Description:', content: description };
|
||||
}
|
||||
|
||||
function prepareValueSection(value) {
|
||||
return value !== undefined && { header: 'Value:', content: value };
|
||||
}
|
||||
|
||||
function prepareCommandsSection(commands) {
|
||||
return commands.length && {
|
||||
header: 'Commands:',
|
||||
content: commands.map(command => ({
|
||||
name: command.name,
|
||||
summary: command.description
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
function prepareOptions(options) {
|
||||
options = options.slice(0);
|
||||
|
||||
const variadicArguments = options.find(option => option.variadic);
|
||||
if (variadicArguments) {
|
||||
// options = options.filter(option => option !== variadicArguments);
|
||||
}
|
||||
|
||||
const optionsSection = {
|
||||
header: 'Options:',
|
||||
optionList: options.map(option => {
|
||||
let description = option.required && `[red]{Required}`;
|
||||
if(option.description) {
|
||||
description = description ? `${description} - ${option.description}` : option.description;
|
||||
}
|
||||
|
||||
return {
|
||||
name: option.name,
|
||||
description,
|
||||
alias: option.alias,
|
||||
typeLabel: option.type && `[underline]{${option.type}}`
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
return { options, variadicArguments, optionsSection };
|
||||
}
|
||||
|
||||
function prepareUsageSection(command, options = [], variadicArguments, hasSubcommand, subcommandRequired, subcommandsDelimiter) {
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
|
||||
let usage = [];
|
||||
|
||||
let usageText = `$ ${command}`;
|
||||
|
||||
let usageOptions = options.length ? options.some(option => option.required) ? '<options>' : '[options]' : '';
|
||||
if (usageOptions) {
|
||||
usageText = `${usageText} ${usageOptions}`
|
||||
}
|
||||
|
||||
if (variadicArguments) {
|
||||
let variadicArgumentsUsage = `${variadicArguments.name}...`;
|
||||
variadicArgumentsUsage = variadicArguments.required ? `<${variadicArgumentsUsage}>` : `[${variadicArgumentsUsage}]`;
|
||||
usageText = `${usageText} ${variadicArgumentsUsage}`
|
||||
}
|
||||
|
||||
if(!subcommandRequired){
|
||||
usage.push(usageText);
|
||||
}
|
||||
|
||||
if (hasSubcommand) {
|
||||
let usageCommand = subcommandRequired ? '<command>' : '[command]';
|
||||
usage.push(`$ ${command} ${usageCommand}`);
|
||||
}
|
||||
|
||||
return { header: 'Usage:', content: usage };
|
||||
}
|
||||
|
||||
function getHelp({ name, description, action, value, commandPath, options = [], commands = [] } = {}, { stripAnsi = false, subcommandsDelimiter } = {}) {
|
||||
const command = getCommandFromPath(commandPath, subcommandsDelimiter);
|
||||
const descriptionSection = prepareDescriptionSection(description);
|
||||
const valueSection = prepareValueSection(value);
|
||||
const commandsSection = prepareCommandsSection(commands);
|
||||
const preparedOptions = prepareOptions(options);
|
||||
const optionsSection = preparedOptions.optionsSection;
|
||||
const usageSection = prepareUsageSection(command, preparedOptions.options, preparedOptions.variadicArguments, commands.length, value === undefined && !action);
|
||||
|
||||
const cmdLineUsageData = [];
|
||||
|
||||
if(descriptionSection){
|
||||
cmdLineUsageData.push(descriptionSection);
|
||||
}
|
||||
|
||||
if(usageSection){
|
||||
cmdLineUsageData.push(usageSection);
|
||||
}
|
||||
|
||||
if(valueSection){
|
||||
cmdLineUsageData.push(valueSection);
|
||||
}
|
||||
|
||||
if(preparedOptions.options.length){
|
||||
cmdLineUsageData.push(optionsSection);
|
||||
}
|
||||
|
||||
if(commandsSection){
|
||||
cmdLineUsageData.push(commandsSection);
|
||||
}
|
||||
|
||||
let helpContent = commandLineUsage(cmdLineUsageData);
|
||||
if (stripAnsi) {
|
||||
helpContent = stripAnsiFn(helpContent);
|
||||
}
|
||||
|
||||
return helpContent;
|
||||
}
|
||||
|
||||
module.exports = getHelp;
|
||||
249
node_modules/cliss/lib/cliss.js
generated
vendored
Normal file
249
node_modules/cliss/lib/cliss.js
generated
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
const yargsParser = require('yargs-parser');
|
||||
const { prepareArgs, prepareArgsAndCall } = require('object-to-arguments');
|
||||
const { inspectParameters, getParametersNames } = require('inspect-parameters-declaration');
|
||||
const pipeFn = require('pipe-functions');
|
||||
const getStdin = require('get-stdin');
|
||||
const getHelp = require('./cli-help');
|
||||
const deepMerge = require('deepmerge')
|
||||
|
||||
const defaultOptions = {
|
||||
command: {
|
||||
subcommandsDelimiter: undefined
|
||||
},
|
||||
options: {
|
||||
validateRequiredParameters: false
|
||||
},
|
||||
version: {
|
||||
option: 'version'
|
||||
},
|
||||
help: {
|
||||
option: 'help',
|
||||
stripAnsi: false
|
||||
}
|
||||
};
|
||||
|
||||
function callCommand(command, parsedArgs, optionsPipe) {
|
||||
if (command && (command.value || command.action)) {
|
||||
if (command.value) {
|
||||
return execCommandPipeline(() => command.value, parsedArgs, command.pipe, optionsPipe);
|
||||
}
|
||||
|
||||
return execCommandPipeline(command.action, parsedArgs, command.pipe, optionsPipe);
|
||||
}
|
||||
}
|
||||
|
||||
function removeEOL(str) {
|
||||
return str.replace(RegExp(`${os.EOL}$`), '');
|
||||
}
|
||||
|
||||
function checkStdin(stdinFn, stdinValue, parsedArgs, positionalArgs, argsAfterEndOfOptions) {
|
||||
if (stdinValue === '') {
|
||||
return parsedArgs;
|
||||
}
|
||||
|
||||
stdinValue = removeEOL(stdinValue);
|
||||
return stdinFn(stdinValue, parsedArgs, positionalArgs, argsAfterEndOfOptions);
|
||||
}
|
||||
|
||||
function execCommandPipeline(command, parsedArgs, commandPipe = {}, optionsPipe = {}) {
|
||||
const positionalArgs = parsedArgs._;
|
||||
const argsAfterEndOfOptions = parsedArgs['--'];
|
||||
delete parsedArgs._;
|
||||
delete parsedArgs['--'];
|
||||
|
||||
let pipelineArray = [];
|
||||
|
||||
// Wait for stdin or start passing in parsedArgs
|
||||
let pipeStdin = commandPipe.stdin || optionsPipe.stdin;
|
||||
if (pipeStdin) {
|
||||
pipelineArray.push(getStdin);
|
||||
pipelineArray.push(stdinValue => checkStdin(pipeStdin, stdinValue, parsedArgs, positionalArgs, argsAfterEndOfOptions));
|
||||
} else {
|
||||
pipelineArray.push(parsedArgs);
|
||||
}
|
||||
|
||||
// Options Before
|
||||
if (optionsPipe.before) {
|
||||
pipelineArray.push(args => optionsPipe.before(args, positionalArgs, argsAfterEndOfOptions));
|
||||
}
|
||||
|
||||
// Command Before
|
||||
if (commandPipe.before) {
|
||||
pipelineArray.push(args => commandPipe.before(args, positionalArgs, argsAfterEndOfOptions));
|
||||
}
|
||||
|
||||
// Main Command
|
||||
pipelineArray.push(args => prepareArgsAndCall(command, args, ...positionalArgs));
|
||||
|
||||
// Command After
|
||||
if (commandPipe.after) {
|
||||
pipelineArray.push(result => commandPipe.after(result, parsedArgs, positionalArgs, argsAfterEndOfOptions));
|
||||
}
|
||||
|
||||
// Options After
|
||||
if (optionsPipe.after) {
|
||||
pipelineArray.push(result => optionsPipe.after(result, parsedArgs, positionalArgs, argsAfterEndOfOptions));
|
||||
}
|
||||
|
||||
// Exec pipeline
|
||||
const pipeResult = pipeFn(...pipelineArray);
|
||||
|
||||
// Output Promises
|
||||
if (pipeResult && pipeResult.then) {
|
||||
return pipeResult
|
||||
.then(result => result !== undefined && console.log(result))
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
// console.log('pipeResult', command\);
|
||||
|
||||
// Output
|
||||
if (pipeResult !== undefined) {
|
||||
console.log(pipeResult);
|
||||
}
|
||||
}
|
||||
|
||||
function matchCommandFromArgs(args, command, commandPath = []) {
|
||||
commandPath.push(command.name);
|
||||
|
||||
if (command.commands) {
|
||||
for (let subcommand of command.commands) {
|
||||
if (subcommand.name === args[0]) {
|
||||
return matchCommandFromArgs(args.slice(1), subcommand, commandPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
command.commandPath = commandPath;
|
||||
return { command, args };
|
||||
}
|
||||
|
||||
function matchDelimitedSubcommand(subcommandArg = [], command, subcommandDelimiter, commandPath = []) {
|
||||
subcommandArg = subcommandArg.constructor === Array ? subcommandArg : subcommandArg.split(subcommandDelimiter);
|
||||
|
||||
for (let subcommand of command.commands) {
|
||||
if (subcommand.name === subcommandArg[0]) {
|
||||
const nextSubcommand = subcommandArg.slice(1);
|
||||
if (nextSubcommand.length) {
|
||||
return matchDelimitedSubcommand(nextSubcommand, subcommand, subcommandDelimiter, commandPath);
|
||||
} else {
|
||||
return subcommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function matchCommand(args, command, subcommandsDelimiter) {
|
||||
|
||||
if (subcommandsDelimiter && command.commands) {
|
||||
const matchedSubcommand = matchDelimitedSubcommand(args[0], command, subcommandsDelimiter);
|
||||
if (matchedSubcommand) {
|
||||
const commandPath = [command.name].concat(args[0].split(subcommandsDelimiter));
|
||||
command = matchedSubcommand;
|
||||
args = args.slice(1);
|
||||
|
||||
command.commandPath = commandPath;
|
||||
return { command, args };
|
||||
}
|
||||
}
|
||||
|
||||
return matchCommandFromArgs(args.slice(0), command);
|
||||
}
|
||||
|
||||
function buildOptionsFromParametersAndSpec(action, optionsSpec) {
|
||||
// Build options from functions parameters and merge with options spec
|
||||
return getParametersNames(action).map(parameter => {
|
||||
const option = { name: parameter };
|
||||
|
||||
const [, variadic] = parameter.match(/^\.{3}(.*)/) || [];
|
||||
if (variadic) {
|
||||
option.name = variadic;
|
||||
option.variadic = true;
|
||||
}
|
||||
|
||||
const optionSpec = (optionsSpec && optionsSpec.find(optionSpec => optionSpec.name === option.name)) || {};
|
||||
return Object.assign(option, optionSpec);
|
||||
});
|
||||
}
|
||||
|
||||
function buildYargsParserOptions(options) {
|
||||
return options.reduce((result, option) => {
|
||||
// yargsParser option type
|
||||
if (option.type) {
|
||||
const optionType = option.type.toString().toLowerCase();
|
||||
result[optionType] = result[optionType] || [];
|
||||
result[optionType].push(option.name);
|
||||
}
|
||||
|
||||
// yargsParser option alias
|
||||
if (option.alias) {
|
||||
result.alias = result.alias || {};
|
||||
result.alias[option.name] = option.alias
|
||||
}
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function parseArgs(args, parserOptions) {
|
||||
return yargsParser(args, Object.assign({
|
||||
configuration: {
|
||||
'boolean-negation': false,
|
||||
'populate--': true
|
||||
}
|
||||
}, parserOptions));
|
||||
}
|
||||
|
||||
function cliss(cliSpec, clissOptions = {}, argv) {
|
||||
if (cliSpec.constructor === Function) {
|
||||
cliSpec = {
|
||||
action: cliSpec
|
||||
};
|
||||
}
|
||||
|
||||
clissOptions = deepMerge(defaultOptions, clissOptions);
|
||||
|
||||
const argsArray = argv || process.argv.slice(2);
|
||||
|
||||
const { command, args } = matchCommand(argsArray.slice(0), cliSpec, clissOptions.command.subcommandsDelimiter);
|
||||
|
||||
command.options = buildOptionsFromParametersAndSpec(command.action, command.options);
|
||||
|
||||
const yargsParserOptions = buildYargsParserOptions(command.options);
|
||||
const parsedArgs = parseArgs(args, yargsParserOptions);
|
||||
|
||||
// Show version if --version is passed in (disabled if { versionOption: falsey })
|
||||
if ((clissOptions.version.option && parsedArgs[clissOptions.version.option]) && (command.version || cliSpec.version)) {
|
||||
return console.log(command.version || cliSpec.version);
|
||||
}
|
||||
|
||||
const helpOptions = Object.assign({}, clissOptions.help, { subcommandsDelimiter: clissOptions.command.subcommandsDelimiter });
|
||||
|
||||
// Show help if the command doesn't have an action or value
|
||||
if (!command.action && !command.value) {
|
||||
return console.log(getHelp(command, helpOptions));
|
||||
}
|
||||
|
||||
// Show help if the option says to validateRequiredParameters and some of then are not being passed in
|
||||
if (clissOptions.options.validateRequiredParameters) {
|
||||
const everyRequiredOptionsAreSet = command.options.filter(option => option.required).every(requiredOption => {
|
||||
return parsedArgs[requiredOption.name] !== undefined;
|
||||
});
|
||||
|
||||
if (!everyRequiredOptionsAreSet) {
|
||||
return console.log(getHelp(command, helpOptions));
|
||||
}
|
||||
}
|
||||
|
||||
// Show help if --help is passed in
|
||||
if (clissOptions.help.option && parsedArgs[clissOptions.help.option]) {
|
||||
return console.log(getHelp(command, helpOptions));
|
||||
}
|
||||
|
||||
callCommand(command, parsedArgs, clissOptions.pipe);
|
||||
}
|
||||
|
||||
module.exports = cliss;
|
||||
36
node_modules/cliss/package.json
generated
vendored
Normal file
36
node_modules/cliss/package.json
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "cliss",
|
||||
"version": "0.0.2",
|
||||
"description": "CLI Simple, Stupid. Automatic discovery of parameters names. Provides an easy and minimal setup by passing in only a function reference without the need of declaring all expected options names or create a help section by hand. Support to sync / async. Support to subcommands down to N levels.",
|
||||
"main": "./lib/cliss.js",
|
||||
"scripts": {
|
||||
"test": "mocha ./test/main.test.js ./test/main.test.pipe.stdin.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"command-line interface",
|
||||
"command line",
|
||||
"async",
|
||||
"minimal",
|
||||
"simple"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DiegoZoracKy/cliss"
|
||||
},
|
||||
"dependencies": {
|
||||
"command-line-usage": "^4.0.1",
|
||||
"deepmerge": "^2.0.0",
|
||||
"get-stdin": "^5.0.1",
|
||||
"inspect-parameters-declaration": "0.0.9",
|
||||
"object-to-arguments": "0.0.8",
|
||||
"pipe-functions": "^1.3.0",
|
||||
"strip-ansi": "^4.0.0",
|
||||
"yargs-parser": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^4.0.1"
|
||||
}
|
||||
}
|
||||
37
node_modules/cliss/test/main.test.js
generated
vendored
Normal file
37
node_modules/cliss/test/main.test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { exec } = require('child_process');
|
||||
|
||||
const testsPath = path.resolve(__dirname, './specs');
|
||||
const tests = fs.readdirSync(testsPath);
|
||||
|
||||
tests.forEach(test => {
|
||||
describe(test, function() {
|
||||
const modulePath = path.resolve(testsPath, test);
|
||||
const specs = require(path.resolve(modulePath, 'specs.js'));
|
||||
|
||||
specs.forEach(spec => {
|
||||
const { input, output, description } = spec;
|
||||
|
||||
it(description || input, function() {
|
||||
return execCli(modulePath, input).then(result => assert.equal(result, output));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function execCli(moduleCliPath, args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cmd = `node ${moduleCliPath} ${args}`;
|
||||
exec(cmd, (err, stdout, stderr) => {
|
||||
if (err || stderr) {
|
||||
return reject(err || stderr);
|
||||
}
|
||||
|
||||
resolve(stdout.replace(/ +$/gm, '').replace(/\n$/, ''));
|
||||
}).stdin.end();
|
||||
});
|
||||
}
|
||||
28
node_modules/cliss/test/main.test.pipe.stdin.js
generated
vendored
Normal file
28
node_modules/cliss/test/main.test.pipe.stdin.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { exec } = require('child_process');
|
||||
|
||||
const testsPath = path.resolve(__dirname, './specs/cliss-options');
|
||||
|
||||
describe('stdin', function(){
|
||||
it('command.pipe.stdin', function(){
|
||||
return execCli(testsPath, 'nested1')
|
||||
.then(result => assert.equal(result, 'nested1:viastdinoptionsPipe'));
|
||||
})
|
||||
})
|
||||
|
||||
function execCli(moduleCliPath, args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cmd = `echo "VIASTDIN" | node ${moduleCliPath} ${args}`;
|
||||
exec(cmd, (err, stdout, stderr) => {
|
||||
if (err || stderr) {
|
||||
return reject(err || stderr);
|
||||
}
|
||||
|
||||
resolve(stdout.replace(/ +$/gm, '').replace(/\n$/, ''));
|
||||
}).stdin.end();
|
||||
});
|
||||
}
|
||||
59
node_modules/cliss/test/specs/cliss-options/index.js
generated
vendored
Normal file
59
node_modules/cliss/test/specs/cliss-options/index.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
const cliss = require('../../../');
|
||||
|
||||
const cliSpec = {
|
||||
name: 'main',
|
||||
options: [{
|
||||
name: 'param1',
|
||||
description: 'param1 description',
|
||||
required: true
|
||||
}],
|
||||
action: (param1 = 'defaultParam1', param2) => `mainOutput`,
|
||||
commands: [{
|
||||
name: 'nested1',
|
||||
action: param1 => {
|
||||
return `nested1:` + param1;
|
||||
},
|
||||
pipe: {
|
||||
stdin: input => {
|
||||
return {
|
||||
param1: input
|
||||
};
|
||||
}
|
||||
},
|
||||
commands: [{
|
||||
name: 'nested1.1',
|
||||
action: (param1 = 'defaultParam1', param2) => {
|
||||
return `nested1-nested1.1:` + param1;
|
||||
},
|
||||
pipe: {
|
||||
after: result => `${result}commandPipe`
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'nested2',
|
||||
action: param1 => {
|
||||
return `nested2:` + param1;
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
cliss(cliSpec, {
|
||||
command: {
|
||||
subcommandsDelimiter: '-'
|
||||
},
|
||||
options: {
|
||||
validateRequiredParameters: true
|
||||
},
|
||||
help: {
|
||||
stripAnsi: true
|
||||
},
|
||||
pipe: {
|
||||
before: args => {
|
||||
args.param1 = args.param1.toLowerCase()
|
||||
return args;
|
||||
},
|
||||
after: result => `${result}optionsPipe`
|
||||
}
|
||||
});
|
||||
28
node_modules/cliss/test/specs/cliss-options/specs.js
generated
vendored
Normal file
28
node_modules/cliss/test/specs/cliss-options/specs.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const tests = [{
|
||||
description: 'options.validateRequiredParameters = true',
|
||||
input: '--param2=A',
|
||||
output: `
|
||||
Usage:
|
||||
|
||||
$ main <options>
|
||||
$ main [command]
|
||||
|
||||
Options:
|
||||
|
||||
--param1 Required - param1 description
|
||||
--param2
|
||||
|
||||
Commands:
|
||||
|
||||
nested1
|
||||
nested2
|
||||
`
|
||||
}, {
|
||||
description: `command.subcommandsDelimiter = '-' + options.pipe.before + command.pipe.after`,
|
||||
input: 'nested1-nested1.1 --param1=A',
|
||||
output: `nested1-nested1.1:aoptionsPipecommandPipe`
|
||||
}];
|
||||
|
||||
module.exports = tests;
|
||||
56
node_modules/cliss/test/specs/complex-cases/index.js
generated
vendored
Normal file
56
node_modules/cliss/test/specs/complex-cases/index.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
const cliss = require('../../../');
|
||||
|
||||
const cliSpec = {
|
||||
name: 'main-command',
|
||||
description: 'Main command description',
|
||||
version: '1.0.0',
|
||||
commands: [{
|
||||
name: 'nested-command-1',
|
||||
description: 'nested-command-1 description',
|
||||
version: '2.1.0',
|
||||
options: [{
|
||||
name: 'p1',
|
||||
required: true
|
||||
}, {
|
||||
name: 'p2',
|
||||
required: true,
|
||||
description: 'p2 description'
|
||||
}],
|
||||
action: (p1 = 'p1Default', p2) => {
|
||||
return `${p1}-${p2}`;
|
||||
}
|
||||
}, {
|
||||
name: 'nested-command-promise',
|
||||
action: (...args) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => resolve('promise resolved'), 1500);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
name: 'nested-command-variadic',
|
||||
action: (...args) => {
|
||||
return args.reduce((result, v) => result += v);
|
||||
}
|
||||
}, {
|
||||
name: 'nested-command-set-with-no-action',
|
||||
commands: [{
|
||||
name: 'inner-nested-command-set',
|
||||
action: (param1, param2) => param2 + param1
|
||||
}]
|
||||
}, {
|
||||
name: 'nested-command-set-with-action',
|
||||
action: (param1, param2) => param1 + param2,
|
||||
commands: [{
|
||||
name: 'inner-nested-command-set',
|
||||
action: (param1, param2) => param2 + param2 + param1
|
||||
}]
|
||||
}]
|
||||
};
|
||||
|
||||
cliss(cliSpec, {
|
||||
help: {
|
||||
stripAnsi: true
|
||||
}
|
||||
});
|
||||
144
node_modules/cliss/test/specs/complex-cases/specs.js
generated
vendored
Normal file
144
node_modules/cliss/test/specs/complex-cases/specs.js
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
'use strict';
|
||||
|
||||
const helpOutput = `
|
||||
Description:
|
||||
|
||||
Main command description
|
||||
|
||||
Usage:
|
||||
|
||||
$ main-command <command>
|
||||
|
||||
Commands:
|
||||
|
||||
nested-command-1 nested-command-1 description
|
||||
nested-command-promise
|
||||
nested-command-variadic
|
||||
nested-command-set-with-no-action
|
||||
nested-command-set-with-action
|
||||
`;
|
||||
|
||||
const nestedCommand1HelpOutput = `
|
||||
Description:
|
||||
|
||||
nested-command-1 description
|
||||
|
||||
Usage:
|
||||
|
||||
$ main-command nested-command-1 <options>
|
||||
|
||||
Options:
|
||||
|
||||
--p1 Required
|
||||
--p2 Required - p2 description
|
||||
`;
|
||||
|
||||
const nestedCommandPromiseHelpOutput = `
|
||||
Usage:
|
||||
|
||||
$ main-command nested-command-promise [options] [args...]
|
||||
|
||||
Options:
|
||||
|
||||
--args
|
||||
`;
|
||||
|
||||
const nestedCommandSetWithNoActionHelpOutput= `
|
||||
Usage:
|
||||
|
||||
$ main-command nested-command-set-with-no-action <command>
|
||||
|
||||
Commands:
|
||||
|
||||
inner-nested-command-set
|
||||
`;
|
||||
|
||||
const nestedCommandSetWithActionHelpOutput= `
|
||||
Usage:
|
||||
|
||||
$ main-command nested-command-set-with-action [options]
|
||||
$ main-command nested-command-set-with-action [command]
|
||||
|
||||
Options:
|
||||
|
||||
--param1
|
||||
--param2
|
||||
|
||||
Commands:
|
||||
|
||||
inner-nested-command-set
|
||||
`;
|
||||
|
||||
const tests = [{
|
||||
description: 'Main command version',
|
||||
input: '--version',
|
||||
output: `1.0.0`
|
||||
}, {
|
||||
description: 'Main command help (when there is no args for a command without an action)',
|
||||
input: '',
|
||||
output: helpOutput
|
||||
}, {
|
||||
description: 'Main command help',
|
||||
input: '--help',
|
||||
output: helpOutput
|
||||
}, {
|
||||
description: 'Nested command help',
|
||||
input: 'nested-command-1 --help',
|
||||
output: nestedCommand1HelpOutput
|
||||
}, {
|
||||
description: 'Nested command specific version',
|
||||
input: 'nested-command-1 --version',
|
||||
output: `2.1.0`
|
||||
}, {
|
||||
description: 'Nested command call',
|
||||
input: 'nested-command-1',
|
||||
output: `p1Default-undefined`
|
||||
}, {
|
||||
description: 'Nested command call passing in options / args',
|
||||
input: 'nested-command-1 --p2=P2 --p1=P1',
|
||||
output: `P1-P2`
|
||||
}, {
|
||||
description: 'Nested command help showing variading arguments (based on rest parameters definition)',
|
||||
input: 'nested-command-promise --help',
|
||||
output: nestedCommandPromiseHelpOutput
|
||||
}, {
|
||||
description: 'Nested command version (getting the value from main command)',
|
||||
input: 'nested-command-promise --version',
|
||||
output: `1.0.0`
|
||||
}, {
|
||||
description: 'Nested command call resolving a Promise',
|
||||
input: 'nested-command-promise',
|
||||
output: `promise resolved`
|
||||
}, {
|
||||
description: 'Nested command call variadic arguments',
|
||||
input: 'nested-command-variadic 1 9 8 4',
|
||||
output: `22`
|
||||
}, {
|
||||
description: 'Nested command call variadic arguments (with arbitrary named options)',
|
||||
input: 'nested-command-variadic --a=1 --b=9 --c=8 --d=4',
|
||||
output: `22`
|
||||
}, {
|
||||
description: 'Nested command with no action plus having more nested commands defined --help',
|
||||
input: 'nested-command-set-with-no-action --help',
|
||||
output: nestedCommandSetWithNoActionHelpOutput
|
||||
}, {
|
||||
description: 'Nested command, of an already nested command, call (3 level deep)',
|
||||
input: 'nested-command-set-with-no-action inner-nested-command-set --param1=A --param2=B',
|
||||
output: `BA`
|
||||
}, {
|
||||
description: 'Nested command with action plus having more nested commands defined --help',
|
||||
input: 'nested-command-set-with-action --help',
|
||||
output: nestedCommandSetWithActionHelpOutput
|
||||
}, {
|
||||
description: 'Nested command with action plus having more nested commands defined call',
|
||||
input: 'nested-command-set-with-action --param1=A --param2=B',
|
||||
output: `AB`
|
||||
}, {
|
||||
description: 'Nested command, of an already nested command, call (3 level deep, when the parent also contains an action)',
|
||||
input: 'nested-command-set-with-action inner-nested-command-set --param1=A --param2=B',
|
||||
output: `BBA`
|
||||
}];
|
||||
|
||||
|
||||
|
||||
module.exports = tests;
|
||||
10
node_modules/cliss/test/specs/fn-cli/index.js
generated
vendored
Normal file
10
node_modules/cliss/test/specs/fn-cli/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const cliss = require('../../../');
|
||||
|
||||
const fn = (param1 = 'defaultParam1', param2) => `${param1}-${param2}`;
|
||||
cliss(fn, {
|
||||
help: {
|
||||
stripAnsi: true
|
||||
}
|
||||
});
|
||||
26
node_modules/cliss/test/specs/fn-cli/specs.js
generated
vendored
Normal file
26
node_modules/cliss/test/specs/fn-cli/specs.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const tests = [
|
||||
{
|
||||
description: 'cli function with no object spec definition',
|
||||
input: '--param1=A --param2=B',
|
||||
output: `A-B`
|
||||
},
|
||||
|
||||
{
|
||||
description: 'Passing in only one argument (using default values)',
|
||||
input: '--param2=B',
|
||||
output: `defaultParam1-B`
|
||||
},
|
||||
|
||||
{
|
||||
input: '--help',
|
||||
output: `
|
||||
Options:
|
||||
|
||||
--param1
|
||||
--param2
|
||||
`
|
||||
}];
|
||||
|
||||
module.exports = tests;
|
||||
14
node_modules/cliss/test/specs/simple-cli/index.js
generated
vendored
Normal file
14
node_modules/cliss/test/specs/simple-cli/index.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const cliss = require('../../../');
|
||||
|
||||
const cliSpec = {
|
||||
name: 'simple-cli',
|
||||
action: (param1 = 'defaultParam1', param2) => `${param1}-${param2}`,
|
||||
};
|
||||
|
||||
cliss(cliSpec, {
|
||||
help: {
|
||||
stripAnsi: true
|
||||
}
|
||||
});
|
||||
30
node_modules/cliss/test/specs/simple-cli/specs.js
generated
vendored
Normal file
30
node_modules/cliss/test/specs/simple-cli/specs.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const tests = [
|
||||
{
|
||||
description: 'object specification + passing in options / args',
|
||||
input: '--param1=A --param2=B',
|
||||
output: `A-B`
|
||||
},
|
||||
|
||||
{
|
||||
description: 'Passing in only one argument',
|
||||
input: '--param2=B',
|
||||
output: `defaultParam1-B`
|
||||
},
|
||||
|
||||
{
|
||||
input: '--help',
|
||||
output: `
|
||||
Usage:
|
||||
|
||||
$ simple-cli [options]
|
||||
|
||||
Options:
|
||||
|
||||
--param1
|
||||
--param2
|
||||
`
|
||||
}];
|
||||
|
||||
module.exports = tests;
|
||||
Reference in New Issue
Block a user