1 | #!/usr/bin/env node
|
2 |
|
3 | const program = require('commander');
|
4 | const cli = require('../lib/cli');
|
5 | const pkg = require('../package.json');
|
6 |
|
7 | function list(val) {
|
8 | return val.split(',');
|
9 | }
|
10 |
|
11 | function parseAssociateParser(val, req) {
|
12 | const data = val.split(',');
|
13 | if (data.length === 0 || data.length > 2) {
|
14 | throw new TypeError('Incorrectly formatted extension / parser registration. (param: ' + val + ')');
|
15 | }
|
16 | const parser = data[1] || 'defaultParser';
|
17 | const ext = data[0];
|
18 |
|
19 | req[ext] = { parserName: parser };
|
20 | return req;
|
21 | }
|
22 |
|
23 |
|
24 | program
|
25 | .description(pkg.description)
|
26 | .version(pkg.version)
|
27 | .usage('[options] <file ...>')
|
28 | .option(
|
29 | '-A, --associate-parser [ext,parser]',
|
30 | 'associate unknown extensions with bundled parsers (parser optional / default: defaultParser)',
|
31 | parseAssociateParser,
|
32 | {}
|
33 | )
|
34 | .option('-i, --ignore <patterns>', 'add ignore patterns', list, [])
|
35 | .option('-I, --inline-files', 'parse possible inline files', false)
|
36 | .option('-r, --reporter [reporter]', 'use reporter (table|json|xml|markdown|vscode|raw) (default: table)', 'table')
|
37 | .option('-S, --skip-unsupported', 'skip unsupported filetypes', false)
|
38 | .option('-t, --filetype [filetype]', 'force the filetype to parse. Useful for streams (default: .js)')
|
39 | .option('-T, --tags <tags>', 'add additional comment types to find (alongside todo & fixme)', list, [])
|
40 | .option('-x, --exit-nicely', 'exit with exit code 0 even if todos/fixmes are found', false)
|
41 | .on('--help', function() {
|
42 | console.log(' Examples:');
|
43 | console.log('');
|
44 | console.log(' # Check a specific file');
|
45 | console.log(' $ leasot index.js');
|
46 | console.log('');
|
47 | console.log(' # Check php files with glob');
|
48 | console.log(' $ leasot **/*.php');
|
49 | console.log('');
|
50 | console.log(' # Check multiple different filetypes');
|
51 | console.log(' $ leasot app/**/*.js test.rb');
|
52 | console.log('');
|
53 | console.log(' # Use the json reporter');
|
54 | console.log(' $ leasot --reporter json index.js');
|
55 | console.log('');
|
56 | console.log(' # Search for REVIEW comments as well');
|
57 | console.log(' $ leasot --tags review index.js');
|
58 | console.log('');
|
59 | console.log(' # Add ignore pattern to filter matches');
|
60 | console.log(' $ leasot app/**/*.js --ignore "**/custom.js"');
|
61 | console.log('');
|
62 | console.log(' # Search for REVIEW comments as well');
|
63 | console.log(' $ leasot --tags review index.js');
|
64 | console.log('');
|
65 | console.log(' # Check a stream specifying the filetype as coffee');
|
66 | console.log(' $ cat index.coffee | leasot --filetype .coffee');
|
67 | console.log('');
|
68 | console.log(' # Report from leasot parsing and filter todos using `jq`');
|
69 | console.log(
|
70 | ' $ leasot tests/**/*.styl --reporter json | jq \'map(select(.kind == "TODO"))\' | leasot-reporter'
|
71 | );
|
72 | console.log('');
|
73 | })
|
74 | .parse(process.argv);
|
75 |
|
76 | cli(program);
|