-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontent-cli.ts
More file actions
84 lines (70 loc) · 2.64 KB
/
Copy pathcontent-cli.ts
File metadata and controls
84 lines (70 loc) · 2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
import semverSatisfies = require("semver/functions/satisfies");
import { Command } from "commander";
import { Configurator, ModuleHandler } from "./core/command/module-handler";
import { Context } from "./core/command/cli-context";
import { VersionUtils } from "./core/utils/version";
import { logger } from "./core/utils/logger";
/**
* Celonis Content CLI.
*
* This is the main entry point for the CLI.
*/
// Check if the Node.js version satisfies the minimum requirements
const requiredVersion = ">=10.10.0";
if (!semverSatisfies(process.version, requiredVersion)) {
logger.error(
`Node version ${process.version} not supported. Please upgrade your node version to ${requiredVersion}`
);
process.exit(1);
}
async function configureGlobalConfigurationOptions(): Promise<Command> {
const program: Command = new Command();
const currentCliVersion = await VersionUtils.getCurrentCliVersion();
program.version(currentCliVersion);
program.option("-q, --quietmode", "Reduce output to a minimum", false);
program.option("-p, --profile [profile]");
program.option("--debug", "Print debug messages", false);
program.option("--dev", "Development Mode", false);
program.parseOptions(process.argv);
if (!program.opts().quietmode) {
console.log(`Content CLI - (C) Copyright 2025 - Celonis SE - Version ${currentCliVersion}`);
console.log();
}
if (program.opts().debug) {
logger.transports.forEach(t => {
t.level = "debug";
});
}
return program;
}
/**
* To support the legacy command structure, we have to configure some root commands
* that the individual modules will extend.
*/
function configureRootCommands(configurator: Configurator): void {
configurator.command("list")
.description("Commands to list content.")
.alias("ls");
}
async function run(): Promise<void> {
const program = await configureGlobalConfigurationOptions();
const context = new Context(program.opts());
await context.init();
const moduleHandler = new ModuleHandler(program, context);
configureRootCommands(moduleHandler.configurator);
moduleHandler.discoverAndRegisterModules(__dirname, program.opts().dev);
try {
program.parse(process.argv);
} catch (error) {
logger.error(`An unexpected error occurred: ${error}`);
}
}
run();
// catch uncaught exceptions
process.on("uncaughtException", (error: Error, origin: NodeJS.UncaughtExceptionOrigin) => {
console.error("\n💥 UNCAUGHT EXCEPTION!\n");
console.error("Error:", error);
console.error("Origin:", origin);
process.exit(1);
});