diff --git a/bin/cli.js b/bin/cli.js index 84de543..9260c9b 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -14,8 +14,6 @@ import logging from '../src/lib/logger.js'; import SVGLint from '../src/svglint.js'; // @ts-ignore -const gui = new GUI(); - const logger = logging(''); const EXIT_CODES = Object.freeze({ @@ -46,7 +44,7 @@ const cli = meow( ` ${chalk.yellow('Usage:')} ${chalk.bold('svglint')} [--config config.js] [--ci] [--debug] ${chalk.bold('file1.svg file2.svg')} - ${chalk.bold('svglint')} --stdin [--config config.js] [--ci] [--debug] < ${chalk.bold('file1.svg')} + ${chalk.bold('svglint')} --stdin [--config config.js] [--summary] [--ci] [--debug] < ${chalk.bold('file1.svg')} ${chalk.yellow('Options:')} ${chalk.bold('--help')} Display this help text @@ -54,7 +52,8 @@ const cli = meow( ${chalk.bold('--config, -c')} Specify the config file. Defaults to '.svglintrc.js' ${chalk.bold('--debug, -d')} Show debug logs ${chalk.bold('--ci, -C')} Only output to stdout once, when linting is finished - ${chalk.bold('--stdin')} Read an SVG from stdin`, + ${chalk.bold('--stdin')} Read an SVG from stdin + ${chalk.bold('--summary')} Print the summary at the end`, { importMeta: import.meta, flags: { @@ -62,10 +61,13 @@ const cli = meow( debug: {type: 'boolean', alias: 'd'}, ci: {type: 'boolean', alias: 'C'}, stdin: {type: 'boolean'}, + summary: {type: 'boolean', default: true}, }, }, ); +const gui = new GUI({ printSummary: cli.flags.summary }); + process.on('exit', () => { gui.finish(); }); diff --git a/src/cli/gui.js b/src/cli/gui.js index 9219f0e..0ae1617 100644 --- a/src/cli/gui.js +++ b/src/cli/gui.js @@ -15,7 +15,7 @@ const logHistory = Logger.cliConsole; /** @typedef {import("../lib/linting.js")} Linting */ export default class GUI { - constructor() { + constructor({ printSummary = true } = {}) { // Subscribe to global logs Logger.setCLI(true); logHistory.on('msg', () => this.update()); @@ -30,7 +30,7 @@ export default class GUI { summary: new Separator('Summary'), }; this.$log = new Log(logHistory); - this.$summary = new Summary(); + this.$summary = printSummary ? new Summary() : null; /** @type {LintingDisplay[]} */ this.$lintings = []; } @@ -104,7 +104,9 @@ export default class GUI { } } - outp.push('', this.$titles.summary, this.$summary); + if (this.$summary) { + outp.push('', this.$titles.summary, this.$summary); + } if (outp[0] === '') { outp.shift(); } @@ -127,7 +129,7 @@ export default class GUI { */ addLinting(linting) { this.$lintings.push(new LintingDisplay(linting)); - this.$summary.addLinting(linting); + this.$summary?.addLinting(linting); linting.on('rule', () => this.update()); linting.on('done', () => this.update()); }