forked from kucherenko/jscpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
84 lines (72 loc) · 3.32 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { bold, white } from 'colors/safe';
import { Command } from 'commander';
import { IClone, IOptions, JSCPD } from '.';
import { BlamerPostHook } from './hooks/post/blamer';
import { StoresManager } from './stores/stores-manager';
import { getSupportedFormats } from './tokenizer/formats';
import { getOption, prepareOptions } from './utils/options';
const packageJson = require(__dirname + '/../package.json');
export const cli: Command = new Command(packageJson.name)
.version(packageJson.version)
.usage('[options] <path ...>')
.description(packageJson.description);
cli.option(
'-l, --min-lines [number]',
'min size of duplication in code lines (Default is ' + getOption('minLines') + ')'
);
cli.option(
'-k, --min-tokens [number]',
'min size of duplication in code tokens (Default is ' + getOption('minTokens') + ')'
);
cli.option('-x, --max-lines [number]', 'max size of source in lines (Default is ' + getOption('maxLines') + ')');
cli.option(
'-z, --max-size [string]',
'max size of source in bytes, examples: 1kb, 1mb, 120kb (Default is ' + getOption('maxSize') + ')'
);
cli.option(
'-t, --threshold [number]',
'threshold for duplication, in case duplications >= threshold jscpd will exit with error'
);
cli.option('-c, --config [string]', 'path to config file (Default is .cpd.json in <path>)');
cli.option('-i, --ignore [string]', 'glob pattern for files what should be excluded from duplication detection');
cli.option(
'-r, --reporters [string]',
'reporters or list of reporters separated with coma to use (Default is time,console)'
);
cli.option('-o, --output [string]', 'reporters to use (Default is ./report/)');
cli.option(
'-m, --mode [string]',
'mode of quality of search, can be "strict", "mild" and "weak" (Default is "' + getOption('mode') + '")'
);
cli.option('-f, --format [string]', 'format or formats separated by coma (Example php,javascript,python)');
cli.option('-b, --blame', 'blame authors of duplications (get information about authors from git)');
cli.option('-s, --silent', 'do not write detection progress and result to a console');
cli.option('-a, --absolute', 'use absolute path in reports');
cli.option('-n, --noSymlinks', 'dont use symlinks for detection in files');
cli.option('--ignoreCase', 'ignore case of symbols in code (experimental)');
cli.option('-g, --gitignore', 'ignore all files from .gitignore file');
cli.option('--formats-exts [string]', 'list of formats with file extensions (javascript:es,es6;dart:dt)');
// cli.option('--cache', 'Cache results of duplication detection');
cli.option('-d, --debug', 'show debug information(options list and selected files)');
cli.option('--list', 'show list of total supported formats');
cli.option('--xsl-href [string]', '(Deprecated) Path to xsl file');
cli.option('-p, --path [string]', '(Deprecated) Path to repo, use `jscpd <path>`');
cli.parse(process.argv);
const options: IOptions = prepareOptions(cli);
if (cli.list) {
console.log(bold(white('Supported formats: ')));
console.log(getSupportedFormats().join(', '));
process.exit(0);
}
if (cli.debug) {
console.log(bold(white('Options:')));
console.dir(options);
}
const cpd: JSCPD = new JSCPD(options);
if (cpd.options.blame) {
cpd.attachPostHook(new BlamerPostHook());
}
const clones: Promise<IClone[]> = cpd.detectInFiles(options.path);
clones.then(() => {
StoresManager.close();
});