This repository was archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
51 lines (42 loc) · 1.88 KB
/
cli.js
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
/* encoding: utf-8 */
import { Command } from "commander/esm.mjs";
import { parseDataDiffs } from "./job_parse";
import { publishDataDiffs } from "./job_publish";
import { renderDataDiffs } from "./job_publish";
const DEFAULT_GCP_PROJECT = "ds3-dialect-map";
const DEFAULT_GCP_PUBSUB = "data-diff";
const DEFAULT_DEBUG_FLAG = "false";
const program = new Command();
program
.command("publish")
.description("Parses and publishes data diff JSON messages into a Pub/Sub topic")
.argument("<data_file>", "File containing the structured data")
.argument("<diff_file>", "File containing the modifications over the data file")
.option("--gcp-project <project>", "GCP project ID", DEFAULT_GCP_PROJECT)
.option("--gcp-pubsub <topic>", "GCP Pub/Sub topic", DEFAULT_GCP_PUBSUB)
.option("--debug-flag <bool>", "Flag for debug runs", DEFAULT_DEBUG_FLAG)
.action(async (dataFile, diffFile, options) => {
// Options unfold
let gcpProject = options["gcpProject"];
let gcpPubSub = options["gcpPubsub"];
let debugFlag = options["debugFlag"].toLowerCase();
if (debugFlag !== "true" && debugFlag !== "false") {
console.error(`Invalid debug flag: ${debugFlag}`);
process.exit(1);
}
console.info(`Received arguments and options:`);
console.info(`Data file path: ${dataFile}`);
console.info(`Diff file path: ${diffFile}`);
console.info(`GCP Project ID: ${gcpProject}`);
console.info(`GCP PubSub topic: ${gcpPubSub}`);
console.info(`Debug flag value: ${debugFlag}`);
let messages = parseDataDiffs(dataFile, diffFile);
if (debugFlag === "true") {
renderDataDiffs(messages);
}
if (debugFlag === "false") {
await publishDataDiffs(gcpProject, gcpPubSub, messages);
}
});
// CLI arguments parsing
program.parse(process.argv);