Skip to content

Commit

Permalink
feat: double-dash argument as last option in arg line
Browse files Browse the repository at this point in the history
  • Loading branch information
Dror Ben-Gai committed May 4, 2017
1 parent d984cb8 commit 8291ec1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
10 changes: 9 additions & 1 deletion cli/args.js
Expand Up @@ -7,9 +7,17 @@ alias.d = 'debug'; // always make `-d` debug
alias.t = 'test';

function args(processargv) {
// doubleDashArgs is used to signify that all arguments after a '--'
// are taken as is and passed to the next process (see lib/module-info/maven)
var doubleDashArgs = false;
// allows us to support flags with true or false only
var argv = processargv.slice(2).reduce(function reduce(acc, arg) {
if (arg.indexOf('-') === 0) {
if (arg === '--') {
doubleDashArgs = true;
} else if (doubleDashArgs) {
acc._doubleDashArgs = (acc._doubleDashArgs || '') + ' ' + arg;
acc._doubleDashArgs = acc._doubleDashArgs.trim();
} else if (arg.indexOf('-') === 0) {
arg = arg.slice(1);

if (alias[arg] !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion lib/module-info/index.js
Expand Up @@ -3,7 +3,7 @@ var detectFile = require('../detect').detectPackageFile;
module.exports = function getModuleInfo(packageManager, root, options) {
var targetFile = options.file || detectFile(root);
var getInfo = loadModuleInfoForPackageManager(packageManager);
return getInfo(root, targetFile, options.policy);
return getInfo(root, targetFile, options.policy, options._doubleDashArgs);
};

function loadModuleInfoForPackageManager(packageManager) {
Expand Down
17 changes: 11 additions & 6 deletions lib/module-info/maven/index.js
Expand Up @@ -4,14 +4,16 @@ var fs = require('fs');
var path = require('path');
var subProcess = require('../../sub-process');

module.exports = function (root, targetFile, policy) {
return subProcess.execute('mvn', buildArgs(root, targetFile), { cwd: root })
.then(function (result) {
return parse(result.stdout);
});
module.exports = function (root, targetFile, policy, mavenArgs) {
return subProcess.execute('mvn',
buildArgs(root, targetFile, mavenArgs),
{ cwd: root })
.then(function (result) {
return parse(result.stdout);
});
};

function buildArgs(root, targetFile) {
function buildArgs(root, targetFile, mavenArgs) {
// Requires Maven >= 2.2
var args = ['dependency:tree', '-DoutputType=dot'];
if (targetFile) {
Expand All @@ -20,5 +22,8 @@ function buildArgs(root, targetFile) {
}
args.push('--file=' + targetFile);
}
if (mavenArgs) {
args.push(mavenArgs);
}
return args;
}
15 changes: 15 additions & 0 deletions test/args.test.js
@@ -0,0 +1,15 @@
var test = require('tap-only');
var args = require('../cli/args');

test('test command line arguments', function(t) {
t.plan(1);
var cliArgs = [ '/Users/dror/.nvm/versions/node/v6.9.2/bin/node',
'/Users/dror/work/snyk/snyk-internal/cli',
'test',
'--',
'-Paxis',
'-Pjaxen'
];
var result = args(cliArgs);
t.equal(result.options._doubleDashArgs, '-Paxis -Pjaxen');
});
4 changes: 2 additions & 2 deletions test/policy-trust-deep.test.js
Expand Up @@ -8,15 +8,15 @@ test('`snyk test` sees suggested ignore policies', function (t) {
var vulns = res.message.toLowerCase();
t.notEqual(vulns.indexOf('suggests ignoring this issue, with reason: test trust policies'), -1, 'found suggestion to ignore');

t.equal(count('vulnerability found', vulns), 7, 'all 7 vulns found');
t.equal(count('vulnerability found', vulns), 8, 'all 8 vulns found');
});
});

test('`snyk test` ignores when applying `--trust-policies`', function (t) {
return cli.test(dir, { 'trust-policies': true }).catch(function (res) {
var vulns = res.message.trim();
// note: it's 2 vulns
t.equal(count('vulnerability found', vulns), 5, 'only 5 vulns left');
t.equal(count('vulnerability found', vulns), 6, 'only 6 vulns left');
});
});

Expand Down

0 comments on commit 8291ec1

Please sign in to comment.