Skip to content

Commit

Permalink
Add an option --no-summary to not print the summary at the end of the…
Browse files Browse the repository at this point in the history
… report
  • Loading branch information
calixteman committed Aug 30, 2024
1 parent c8403f7 commit a820036
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -46,26 +44,30 @@ 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
${chalk.bold('--version')} Show the current SVGLint version
${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: {
config: {type: 'string', alias: 'c'},
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();
});
Expand Down
10 changes: 6 additions & 4 deletions src/cli/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 = [];
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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());
}
Expand Down

0 comments on commit a820036

Please sign in to comment.