feat(cli): add verbose (vb) flag that can control output of all file … (#74)

* feat(cli): add verbose (vb) flag that can control output of all file paths to console

* docs(README): add -vb description
This commit is contained in:
Sean G. Wright
2017-11-07 09:14:31 -05:00
committed by Kim Biesbjerg
parent 8d1e2c5a2f
commit 14eb09f947
3 changed files with 12 additions and 2 deletions

View File

@@ -93,3 +93,5 @@ Options:
[boolean] [default: false] [boolean] [default: false]
--clean, -c Remove obsolete strings when merging --clean, -c Remove obsolete strings when merging
[boolean] [default: false] [boolean] [default: false]
--verbose, -vb If true, prints all processed file paths to console
[boolean] [default: true]

View File

@@ -82,6 +82,12 @@ export const cli = yargs
default: false, default: false,
type: 'boolean' type: 'boolean'
}) })
.option('verbose', {
alias: 'vb',
describe: 'Log all output to console',
default: true,
type: 'boolean'
})
.exitProcess(true) .exitProcess(true)
.parse(process.argv); .parse(process.argv);

View File

@@ -14,6 +14,7 @@ export interface ExtractTaskOptionsInterface {
sort?: boolean; sort?: boolean;
clean?: boolean; clean?: boolean;
patterns?: string[]; patterns?: string[];
verbose?: boolean;
} }
export class ExtractTask implements TaskInterface { export class ExtractTask implements TaskInterface {
@@ -22,7 +23,8 @@ export class ExtractTask implements TaskInterface {
replace: false, replace: false,
sort: false, sort: false,
clean: false, clean: false,
patterns: [] patterns: [],
verbose: true
}; };
protected _parsers: ParserInterface[] = []; protected _parsers: ParserInterface[] = [];
@@ -64,7 +66,7 @@ export class ExtractTask implements TaskInterface {
let collection: TranslationCollection = new TranslationCollection(); let collection: TranslationCollection = new TranslationCollection();
this._input.forEach(dir => { this._input.forEach(dir => {
this._readDir(dir, this._options.patterns).forEach(path => { this._readDir(dir, this._options.patterns).forEach(path => {
this._out(chalk.gray('- %s'), path); this._options.verbose && this._out(chalk.gray('- %s'), path);
const contents: string = fs.readFileSync(path, 'utf-8'); const contents: string = fs.readFileSync(path, 'utf-8');
this._parsers.forEach((parser: ParserInterface) => { this._parsers.forEach((parser: ParserInterface) => {
collection = collection.union(parser.extract(contents, path)); collection = collection.union(parser.extract(contents, path));