Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cliparse

Package Overview
Dependencies
Maintainers
7
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cliparse - npm Package Compare versions

Comparing version 0.3.1 to 0.3.3

12

package.json
{
"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')
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc