Skip to content

Commit bc29299

Browse files
authored
feat: add Help to CLI (#45)
* feat: add Help to CLI * rename args after rebase
1 parent 0dfdebd commit bc29299

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/cli/arguments.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function validate_arguments(args: ReturnType<typeof parse_arguments>): Cl
6464
export function parse_arguments(args: string[]) {
6565
let { values } = parseArgs({
6666
args,
67-
allowPositionals: true,
6867
options: {
6968
'coverage-dir': {
7069
type: 'string',

src/cli/cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import { program } from './program.js'
55
import { read } from './file-reader.js'
66
import { print as pretty } from './reporters/pretty.js'
77
import { print as tap } from './reporters/tap.js'
8+
import { help } from './help.js'
89

910
async function cli(cli_args: string[]) {
11+
if (!cli_args || cli_args.length === 0 || cli_args.includes('--help') || cli_args.includes('-h')) {
12+
return console.log(help())
13+
}
14+
1015
let params = validate_arguments(parse_arguments(cli_args))
1116
let coverage_data = await read(params['coverage-dir'])
1217
let report = program(

src/cli/help.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { styleText } from 'node:util'
2+
3+
export function help() {
4+
return `
5+
${styleText(['bold'], 'USAGE')}
6+
$ css-coverage --coverage-dir=<dir> --min-coverage=<number> [options]
7+
8+
${styleText('bold', 'OPTIONS')}
9+
Required:
10+
--coverage-dir Where your Coverage JSON files are
11+
--min-coverage Minimum overall CSS coverage [0-1]
12+
13+
Optional:
14+
--min-file-coverage Minimal coverage per file [0-1]
15+
16+
--show-uncovered Which files to show when not meeting
17+
the --min-file-line-coverage threshold
18+
• violations [default] ${styleText('dim', 'show under-threshold files')}
19+
• all ${styleText('dim', 'show partially covered files')}
20+
• none ${styleText('dim', 'do not show files')}
21+
22+
--reporter How to show the results
23+
• pretty [default]
24+
• tap
25+
• json
26+
27+
${styleText('bold', 'EXAMPLES')}
28+
${styleText('dim', '# analyze all .json files in ./coverage; require 80% overall coverage')}
29+
$ css-coverage --coverage-dir=./coverage --min-coverage=0.8
30+
31+
${styleText('dim', '# Require 50% coverage per file')}
32+
$ css-coverage --coverage-dir=./coverage --min-coverage=0.8 --min-file-coverage=0.5
33+
34+
${styleText('dim', 'Report JSON')}
35+
$ css-coverage --coverage-dir=./coverage --min-coverage=0.8 --reporter=json
36+
`.trim()
37+
}

0 commit comments

Comments
 (0)