Skip to content

Commit

Permalink
[enhance] #63 Add --quiet flag to supress console output in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreisnz committed Apr 21, 2019
1 parent 3eba177 commit 32df0ad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config = loadConfig(configFile);
const options = combineConfig(config, argv);

//Extract settings
const {from, to, files, isRegex, verbose} = options;
const {from, to, files, isRegex, verbose, quiet} = options;

//Single star globs already get expanded in the command line
options.files = files.reduce((files, file) => {
Expand All @@ -44,12 +44,16 @@ if (isRegex) {
}

//Log
console.log(`Replacing '${from}' with '${to}'`);
if (!quiet) {
console.log(`Replacing '${from}' with '${to}'`);
}

//Replace
try {
const results = replace.sync(options);
successHandler(results, verbose);
if (!quiet) {
successHandler(results, verbose);
}
}
catch (error) {
errorHandler(error);
Expand Down
1 change: 1 addition & 0 deletions lib/helpers/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const defaults = {
countMatches: false,
isRegex: false,
verbose: false,
quiet: false,
dry: false,
glob: {},
cwd: null,
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/success-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const chalk = require('chalk');
/**
* Success handler
*/
module.exports = function successHandler(changes, verbose = false) {
module.exports = function successHandler(changes, verbose) {
if (changes.length > 0) {
console.log(chalk.green(changes.length, 'file(s) were changed'));
if (verbose) {
Expand Down
2 changes: 1 addition & 1 deletion lib/replace-in-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ replaceInFile.sync = function(config) {
//Dry run?
//istanbul ignore if: No need to test console logs
if (dry && verbose) {
console.log(chalk.yellow('Dry run, not making any changes'));
console.log(chalk.yellow('Dry run, not making actual changes'));
}

//Process synchronously and return results
Expand Down

0 comments on commit 32df0ad

Please sign in to comment.