diff --git a/src/cli/arguments.ts b/src/cli/arguments.ts index 0235b0f..77ddc10 100644 --- a/src/cli/arguments.ts +++ b/src/cli/arguments.ts @@ -64,7 +64,6 @@ export function validate_arguments(args: ReturnType): Cl export function parse_arguments(args: string[]) { let { values } = parseArgs({ args, - allowPositionals: true, options: { 'coverage-dir': { type: 'string', diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 0569dfe..8b9bde8 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -5,8 +5,13 @@ import { program } from './program.js' import { read } from './file-reader.js' import { print as pretty } from './reporters/pretty.js' import { print as tap } from './reporters/tap.js' +import { help } from './help.js' async function cli(cli_args: string[]) { + if (!cli_args || cli_args.length === 0 || cli_args.includes('--help') || cli_args.includes('-h')) { + return console.log(help()) + } + let params = validate_arguments(parse_arguments(cli_args)) let coverage_data = await read(params['coverage-dir']) let report = program( diff --git a/src/cli/help.ts b/src/cli/help.ts new file mode 100644 index 0000000..07f99cd --- /dev/null +++ b/src/cli/help.ts @@ -0,0 +1,37 @@ +import { styleText } from 'node:util' + +export function help() { + return ` +${styleText(['bold'], 'USAGE')} + $ css-coverage --coverage-dir= --min-coverage= [options] + +${styleText('bold', 'OPTIONS')} +Required: + --coverage-dir Where your Coverage JSON files are + --min-coverage Minimum overall CSS coverage [0-1] + +Optional: + --min-file-coverage Minimal coverage per file [0-1] + + --show-uncovered Which files to show when not meeting + the --min-file-line-coverage threshold + • violations [default] ${styleText('dim', 'show under-threshold files')} + • all ${styleText('dim', 'show partially covered files')} + • none ${styleText('dim', 'do not show files')} + + --reporter How to show the results + • pretty [default] + • tap + • json + +${styleText('bold', 'EXAMPLES')} + ${styleText('dim', '# analyze all .json files in ./coverage; require 80% overall coverage')} + $ css-coverage --coverage-dir=./coverage --min-coverage=0.8 + + ${styleText('dim', '# Require 50% coverage per file')} + $ css-coverage --coverage-dir=./coverage --min-coverage=0.8 --min-file-coverage=0.5 + + ${styleText('dim', 'Report JSON')} + $ css-coverage --coverage-dir=./coverage --min-coverage=0.8 --reporter=json + `.trim() +}