-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
42 lines (35 loc) · 1.04 KB
/
main.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
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import { parse, parseNested, diff } from "./jfilter.ts";
const { options } = await new Command()
.name("deno-jfilter")
.version("1.4.1")
.description("Create jfilters for edge and vertex rules")
.option(
"-f --file <file>",
"File containing JFilter in JSON format to parse (default expects array)"
)
.option(
"-n --nested",
"Handle nested file input with JFilter values in JSON object"
)
.option(
"-t --test [test]",
"String to compare results against. Not usable with '--nested' option"
)
.parse(Deno.args);
let data = await Deno.readTextFile(options.file).then((f) => JSON.parse(f));
if (options.nested) {
const res = parseNested(data);
console.log(JSON.stringify(res, undefined, 4));
Deno.exit(0);
}
const filter = parse(data);
if (options.test) {
const res = diff(filter, options.test);
if (!res.result) {
console.log("Result did not match");
console.log(res.output);
Deno.exit(1);
}
}
console.log(filter);