@forwardimpact/librpc 0.1.85 → 0.1.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fit-unary.js +30 -9
- package/package.json +2 -1
package/bin/fit-unary.js
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { createCli } from "@forwardimpact/libcli";
|
|
2
4
|
import { createClient, createTracer } from "@forwardimpact/librpc";
|
|
3
5
|
import { createLogger } from "@forwardimpact/libtelemetry";
|
|
4
6
|
|
|
7
|
+
const { version: VERSION } = JSON.parse(
|
|
8
|
+
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const definition = {
|
|
12
|
+
name: "fit-unary",
|
|
13
|
+
version: VERSION,
|
|
14
|
+
description: "Make a unary gRPC call to a service",
|
|
15
|
+
usage: "fit-unary <service> <method> [json-request]",
|
|
16
|
+
options: {
|
|
17
|
+
help: { type: "boolean", short: "h", description: "Show this help" },
|
|
18
|
+
version: { type: "boolean", description: "Show version" },
|
|
19
|
+
json: { type: "boolean", description: "Output help as JSON" },
|
|
20
|
+
},
|
|
21
|
+
examples: ['fit-unary memory GetWindow \'{"resource_id":"..."}\''],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const cli = createCli(definition);
|
|
25
|
+
const logger = createLogger("cli");
|
|
26
|
+
|
|
5
27
|
/**
|
|
6
28
|
* Makes a unary gRPC call to a service
|
|
7
|
-
* Usage: fit-unary <service> <method> [json-request]
|
|
8
29
|
* @returns {Promise<void>}
|
|
9
30
|
*/
|
|
10
31
|
async function main() {
|
|
11
|
-
const
|
|
32
|
+
const parsed = cli.parse(process.argv.slice(2));
|
|
33
|
+
if (!parsed) process.exit(0);
|
|
34
|
+
|
|
35
|
+
const [service, method, requestJson] = parsed.positionals;
|
|
12
36
|
if (!service || !method) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'Example: fit-unary memory GetWindow \'{"resource_id":"..."}\'',
|
|
16
|
-
);
|
|
17
|
-
process.exit(1);
|
|
37
|
+
cli.usageError("expected arguments: <service> <method> [json-request]");
|
|
38
|
+
process.exit(2);
|
|
18
39
|
}
|
|
19
40
|
|
|
20
41
|
const request = requestJson ? JSON.parse(requestJson) : {};
|
|
21
|
-
const logger = createLogger("cli");
|
|
22
42
|
const tracer = await createTracer("cli");
|
|
23
43
|
const client = await createClient(service, logger, tracer);
|
|
24
44
|
|
|
@@ -27,6 +47,7 @@ async function main() {
|
|
|
27
47
|
}
|
|
28
48
|
|
|
29
49
|
main().catch((error) => {
|
|
30
|
-
|
|
50
|
+
logger.exception("main", error);
|
|
51
|
+
cli.error(error.message);
|
|
31
52
|
process.exit(1);
|
|
32
53
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forwardimpact/librpc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.87",
|
|
4
4
|
"description": "gRPC framework and utilities for Guide",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "D. Olsson <hi@senzilla.io>",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"test": "bun run node --test test/*.test.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@forwardimpact/libcli": "^0.1.0",
|
|
20
21
|
"@forwardimpact/libconfig": "^0.1.58",
|
|
21
22
|
"@forwardimpact/libtelemetry": "^0.1.22",
|
|
22
23
|
"@forwardimpact/libutil": "^0.1.60",
|