forked from viszkoktamas/ossf-sast-ml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
60 lines (54 loc) · 1.66 KB
/
cli.js
File metadata and controls
60 lines (54 loc) · 1.66 KB
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
const optionator = require("optionator");
const lint = require("./lint");
module.exports = {
async execute(args) {
if (Array.isArray(args)) {
console.log("CLI args: " + args.slice(2));
}
let opt;
let options;
try {
opt = optionator({
prepend: "node tool [options] [file/dir...]",
defaults: {
concatRepeatedArrays: true,
mergeRepeatedObjects: true
},
options: [
{
heading: "Options"
},
{
option: "output-file",
alias: "o",
type: "path::String",
default: "result.json",
description: "Specify file to write report to"
},
{
option: "help",
alias: "h",
type: "Boolean",
description: "Show help"
}
]
})
options = opt.parse(args);
} catch (error) {
console.log(error.message);
return 2;
}
if (options.help) {
console.log(opt.generateHelp());
return 0;
}
let files = options._;
if (files.length === 0) {
console.error("Error: No files or project specified.");
console.log(opt.generateHelp());
return 1;
}
await lint.execute(files, options.outputFile);
return 0;
}
};