Initial commit, 90% there
This commit is contained in:
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