MCPcopy Create free account
hub / github.com/Snapchat/Valdi / command

Function command

npm_modules/cli/src/utils/errorUtils.ts:38–58  ·  view source on GitHub ↗
(argv: T)

Source from the content-addressed store, hash-verified

36
37export function makeCommandHandler<T>(cb: (argv: ArgumentsResolver<T>) => Promise<void>): (argv: T) => void {
38 const command = async (argv: T) => {
39 const argumentsResolver = new ArgumentsResolver(argv);
40 try {
41 await cb(argumentsResolver);
42 process.exitCode = 0;
43 } catch (error) {
44 process.exitCode = 1;
45
46 if (error instanceof CliError) {
47 // Managed Error
48 console.log(wrapInColor(error.message, error.textColor));
49 } else if (error instanceof Error) {
50 // Unmanaged Error
51 console.log(error.stack);
52 console.log(wrapInColor(error.message, ANSI_COLORS.RED_COLOR));
53 } else {
54 // Something went really wrong
55 throw error;
56 }
57 }
58 };
59
60 return (argv: T) => {
61 void command(argv);

Callers 1

makeCommandHandlerFunction · 0.85

Calls 3

wrapInColorFunction · 0.90
logMethod · 0.65
cbFunction · 0.50

Tested by

no test coverage detected