MCPcopy Create free account
hub / github.com/Redocly/redocly-cli / commandWrapper

Function commandWrapper

packages/cli/src/wrapper.ts:8–42  ·  view source on GitHub ↗
(
  commandHandler: (argv: T, config: Config, version: string) => Promise<void>
)

Source from the content-addressed store, hash-verified

6import type { CommandOptions } from './types';
7
8export function commandWrapper<T extends CommandOptions>(
9 commandHandler: (argv: T, config: Config, version: string) => Promise<void>
10) {
11 return async (argv: Arguments<T>) => {
12 let code: ExitCode = 2;
13 let hasConfig;
14 let telemetry;
15 try {
16 if (argv.config && !doesYamlFileExist(argv.config)) {
17 exitWithError('Please, provide valid path to the configuration file');
18 }
19 const config: Config = (await loadConfigAndHandleErrors({
20 configPath: argv.config,
21 customExtends: argv.extends as string[] | undefined,
22 region: argv.region as Region,
23 files: argv.files as string[] | undefined,
24 processRawConfig: lintConfigCallback(argv as T & Record<string, undefined>, version),
25 })) as Config;
26 telemetry = config.telemetry;
27 hasConfig = !config.styleguide.recommendedFallback;
28 code = 1;
29 await commandHandler(argv, config, version);
30 code = 0;
31 } catch (err) {
32 // Do nothing
33 } finally {
34 if (process.env.REDOCLY_TELEMETRY !== 'off' && telemetry !== 'off') {
35 await sendTelemetry(argv, code, hasConfig);
36 }
37 process.once('beforeExit', () => {
38 process.exit(code);
39 });
40 }
41 };
42}

Callers 4

index.tsFile · 0.90
wrapper.test.tsFile · 0.90
lint.test.tsFile · 0.90
bundle.test.tsFile · 0.90

Calls 5

exitWithErrorFunction · 0.90
lintConfigCallbackFunction · 0.90
sendTelemetryFunction · 0.90
doesYamlFileExistFunction · 0.85

Tested by

no test coverage detected