-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.js
More file actions
41 lines (36 loc) · 1.64 KB
/
cli.js
File metadata and controls
41 lines (36 loc) · 1.64 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
// Configure environment variables based on .env file
import "dotenv/config";
import admin from "./administration.js";
import optimize from "./optimize.js";
import zeebe from "./zeebe.js";
import modeler from "./modeler.js";
import camunda8 from "./camunda-8.js";
import processInstances from "./camunda-process-instances.js";
// All API objects accessible to the CLI app are included here.
// The name of each property translates to an API object that can be called by the CLI.
// e.g. if we export a property named `admin`, you can run `npm run cli admin <action>`.
const APIs = { admin, optimize, zeebe, modeler, camunda8, processInstances };
// Parse the arguments passed into the CLI, and direct a specific action to a specific API object.
// Example: `npm run cli administration list` will find the arguments `administration` and `list`,
// and call the `list` method on the `administration` API object.
// The first two elements are the node executable and file path.
const args = process.argv.slice(2);
if (args.length > 0) {
// The first remaining argument is the name of the API object (e.g. `administration`).
const apiName = args[0];
const API = APIs[apiName];
if (API === undefined) {
throw new Error("Invalid API name.");
}
// The second remaining argument is the name of the action to take (e.g. `list`).
const actionName = args[1];
const action = API[actionName];
if (action === undefined) {
throw new Error("Invalid action name.");
}
// Pass all other remaining arguments into the action method.
const restOfArgs = args.slice(2);
await action(restOfArgs);
} else {
throw new Error("No arguments provided.");
}