Comparing version 0.3.1 to 0.3.3
{ | ||
"name": "cliparse", | ||
"version": "0.3.1", | ||
"version": "0.3.3", | ||
"description": "Declarative CLI parsing for node apps", | ||
"main": "src/cliparse.js", | ||
"dependencies": { | ||
"bluebird": "^3.5.0", | ||
"lodash": "^4.17.11", | ||
"minimist": "^1.2.0" | ||
"bluebird": "^3.7.2", | ||
"lodash": "^4.17.20", | ||
"minimist": "^1.2.5" | ||
}, | ||
"devDependencies": { | ||
"tap": "^12.1.1", | ||
"tap": "^14.11.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.6.3" | ||
"tape": "^5.1.1" | ||
}, | ||
@@ -16,0 +16,0 @@ "scripts": { |
@@ -183,5 +183,14 @@ var _ = require("lodash"); | ||
function getCommandsOfCommand(command) { | ||
return _.reduce(command.commands, (commands, command) => { | ||
if (command.commands.length > 0) { | ||
return commands.concat(getCommandsOfCommand(command)); | ||
} else { | ||
return commands.concat([command]); | ||
} | ||
}, [command]); | ||
} | ||
command.getFlagNames = function(cmd) { | ||
return _([cmd]) | ||
.concat(cmd.commands) | ||
return _(getCommandsOfCommand(cmd)) | ||
.flatMap('options') | ||
@@ -194,6 +203,4 @@ .reject(function(opt) { return opt.expects_value; }) | ||
command.getOptionNames = function (cmd) { | ||
return _([cmd]) | ||
.concat(cmd.commands) | ||
return _(getCommandsOfCommand(cmd)) | ||
.flatMap('options') | ||
@@ -200,0 +207,0 @@ .filter(function(opt) { return opt.expects_value; }) |
@@ -57,31 +57,49 @@ var test = require("tape"); | ||
test('retrieve flags', function(t) { | ||
t.plan(2); | ||
t.plan(3); | ||
var flag1 = cliparse.flag('flag-one'); | ||
var flag2 = cliparse.flag('flag-two', { aliases: ["f"] }); | ||
var flag3 = cliparse.flag('flag-three', { aliases: ["x"]}); | ||
var option1 = cliparse.option('opt-one'); | ||
var option2 = cliparse.option('opt-two', { aliases: ["o"] }); | ||
var option3 = cliparse.option('opt-three', { aliases: ["t"]}); | ||
var cmd1 = cliparse.command('name', { options: [flag1, option2]}); | ||
var cmd2 = cliparse.command('name', { options: [flag1, option1], commands: [ cliparse.command('inner', { options: [flag2, option2] })]}); | ||
var cmd3 = cliparse.command('name', { options: [flag1, option1], commands: [ | ||
cliparse.command('inner', { options: [flag2, option2], commands: [ | ||
cliparse.command('second-inner', { options: [flag3, option3] }), | ||
]}) | ||
]}); | ||
var r1 = command.getFlagNames(cmd1); | ||
var r2 = command.getFlagNames(cmd2); | ||
var r3 = command.getFlagNames(cmd3); | ||
t.same(r1, ['flag-one'], 'simple command'); | ||
t.same(r2, ['flag-one', 'flag-two', 'f'], 'nested commands'); | ||
t.same(r3, ['flag-one', 'flag-two', 'f', 'flag-three', 'x'], 'nested commands two levels'); | ||
}); | ||
test('retrieve option names', function(t) { | ||
t.plan(2); | ||
t.plan(3); | ||
var flag1 = cliparse.flag('flag-one'); | ||
var flag2 = cliparse.flag('flag-two', { aliases: ["f"] }); | ||
var flag3 = cliparse.flag('flag-three', { aliases: ["x"]}); | ||
var option1 = cliparse.option('opt-one'); | ||
var option2 = cliparse.option('opt-two', { aliases: ["o"] }); | ||
var option3 = cliparse.option('opt-three', { aliases: ["t"]}); | ||
var cmd1 = cliparse.command('name', { options: [flag1, option2]}); | ||
var cmd2 = cliparse.command('name', { options: [flag1, option1], commands: [ cliparse.command('inner', { options: [flag2, option2] })]}); | ||
var cmd3 = cliparse.command('name', { options: [flag1, option1], commands: [ | ||
cliparse.command('inner', { options: [flag2, option2], commands: [ | ||
cliparse.command('second-inner', { options: [flag3, option3] }), | ||
]}) | ||
]}); | ||
var r1 = command.getOptionNames(cmd1); | ||
var r2 = command.getOptionNames(cmd2); | ||
var r3 = command.getOptionNames(cmd3); | ||
t.same(r1, ['opt-two', 'o'], 'simple command'); | ||
t.same(r2, ['opt-one', 'opt-two', 'o'], 'nested commands'); | ||
t.same(r3, ['opt-one', 'opt-two', 'o', 'opt-three', 't'], 'nested commands two levels'); | ||
}); | ||
@@ -95,2 +113,2 @@ | ||
t.same(r.success, undefined, 'must fail on unknown options') | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
61547
1295
Updatedbluebird@^3.7.2
Updatedlodash@^4.17.20
Updatedminimist@^1.2.5