Skip to content

Commit

Permalink
Log info and errors only if verbose flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
taktran committed Aug 9, 2019
1 parent 2f3a4f3 commit 77d6516
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 59 deletions.
18 changes: 14 additions & 4 deletions lib/ebi/ebi-log.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const { logText, logJson } = require('../log-result');
const { RESULT_TYPES } = require('./result-types');
const { withErrorMessage } = require('../create-result');

const logOutput = ({ json, output }) => {
const logOutput = ({ verbose, json, output }) => {
const { type } = output;

if (json) {
logJson(output);
} else {
// Ignore non-matches if not in verbose mode
if (type !== RESULT_TYPES.match && !verbose) {
return;
}
logText(output);
}
};
Expand All @@ -16,18 +23,21 @@ const logOutput = ({ json, output }) => {
* @param {boolean} json - whether to log in json or plain text
* @param {array} arrayList - repository list
*/
exports.ebiLog = ({ ebiSearch, json }) => repoList => {
exports.ebiLog = ({ ebiSearch, json, verbose }) => repoList => {
return ebiSearch(repoList)
.then(({ resultsAsync }) => {
const results = resultsAsync.map(result => {
return result
.then(output => logOutput({ json, output }))
.catch(error => logOutput({ json, output: error }));
.then(output => logOutput({ verbose, json, output }))
.catch(error =>
logOutput({ verbose, json, output: error })
);
});
return Promise.all(results);
})
.catch(({ message }) =>
logOutput({
verbose,
json,
output: withErrorMessage(`ERROR: ${message}`)
})
Expand Down
10 changes: 7 additions & 3 deletions src/commands/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
withLimit,
withRegex,
withJson,
withRepoList
withRepoList,
withVerbose
} = require('./shared');

exports.command = 'contents <filepath> [search] [repo..]';
Expand All @@ -22,7 +23,8 @@ exports.builder = yargs => {
withRegex,
withToken,
withLimit,
withRepoList
withRepoList,
withVerbose
]);
return baseConfig(yargs)
.positional('filepath', {
Expand All @@ -43,6 +45,7 @@ exports.handler = ({
regex,
limit,
json,
verbose,
repo: repoList
} = {}) => {
return ebiLog({
Expand All @@ -53,6 +56,7 @@ exports.handler = ({
regex,
limit
}),
json
json,
verbose
})(repoList);
};
10 changes: 7 additions & 3 deletions src/commands/package-engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
withLimit,
withRegex,
withJson,
withRepoList
withRepoList,
withVerbose
} = require('./shared');

exports.command = 'package:engines [search] [repo..]';
Expand All @@ -24,7 +25,8 @@ exports.builder = yargs => {
withRegex,
withToken,
withLimit,
withRepoList
withRepoList,
withVerbose
]);
return baseConfig(yargs).positional('search', {
type: 'string',
Expand All @@ -38,6 +40,7 @@ exports.handler = function({
search,
regex,
json,
verbose,
repo: repoList
} = {}) {
return ebiLog({
Expand All @@ -47,6 +50,7 @@ exports.handler = function({
regex,
limit
}),
json
json,
verbose
})(repoList);
};
10 changes: 7 additions & 3 deletions src/commands/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
withLimit,
withRegex,
withJson,
withRepoList
withRepoList,
withVerbose
} = require('./shared');

exports.command = 'package [search] [repo..]';
Expand All @@ -22,7 +23,8 @@ exports.builder = yargs => {
withRegex,
withToken,
withLimit,
withRepoList
withRepoList,
withVerbose
]);
return baseConfig(yargs).positional('search', {
type: 'string',
Expand All @@ -37,6 +39,7 @@ exports.handler = function({
limit,
regex,
json,
verbose,
repo: repoList
} = {}) {
return ebiLog({
Expand All @@ -46,6 +49,7 @@ exports.handler = function({
regex,
limit
}),
json
json,
verbose
})(repoList);
};
10 changes: 9 additions & 1 deletion src/commands/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ const withRepoList = yargs => {
});
};

const withVerbose = yargs => {
return yargs.option('verbose', {
type: 'boolean',
describe: 'Show all info and error messages. Ignored if outputting JSON'
});
};

module.exports = {
withEpilogue,
withLimit,
withToken,
withRegex,
withJson,
withRepoList
withRepoList,
withVerbose
};
Loading

0 comments on commit 77d6516

Please sign in to comment.