Skip to content

Commit

Permalink
feat: adding json options to output json
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlaud committed Mar 22, 2018
1 parent af9975c commit 7f55122
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var argv = require('minimist')(process.argv.slice(2));
var isRelative = require('is-relative');
var path = require('path');
var template, source, output;
var options = {};

if (argv.i) { // input source
source = argv.i; // grab the next item
Expand All @@ -19,6 +20,9 @@ if (argv.o) { // output destination
output = undefined;
}
}
if (argv.json) { // output destination
options = {"json": true};
}
if (argv.f) { // output destination
if(isRelative(argv.f)){
filters = path.join(__dirname, argv.f);
Expand All @@ -35,7 +39,7 @@ if (argv.f) { // output destination



snykFilter.run(source, onReportOutput, filters);
snykFilter.run(source, onReportOutput, filters, options);

function onReportOutput(report) {
if (output) {
Expand Down
17 changes: 13 additions & 4 deletions lib/snyk-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ function readInputFromStdin(reportCallback) {
});
}

function run(source, reportCallback, filters, options = null) {
function run(source, reportCallback, filters, cliOptions = null) {
//options = options;

try {
var ymlFileInJSON = yaml.safeLoad(fs.readFileSync(filters, 'utf8'));
customFilters = ymlFileInJSON.customFilters;
} catch (e) {
console.log("Error loading yml file" + e);
}

if(options) options = options;
if(cliOptions && cliOptions.json) options.json = cliOptions.json;

try {
if (source) {
Expand All @@ -79,9 +81,16 @@ function processResults(data, filterString, passString, failMsg){
//.then((filteredData) => aggregate(filteredData))
//.then((processedData) => {reportCallback(processedData)})
.then((processedData) => {

//console.log(processedData);
var response = snykDisplay.displayResult(processedData, options);
console.log(response);
if(options && options.json){
console.log("json");
console.log(processedData);
} else {
var response = snykDisplay.displayResult(processedData, options);
console.log(response);
}

})
.catch((error) => {
console.error("filter failed");
Expand Down

0 comments on commit 7f55122

Please sign in to comment.