( fn: T, )
| 28 | // Related issue: https://github.com/yargs/yargs/issues/2118 |
| 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 30 | export function logErrorBeforeThrow<T extends (...args: any[]) => any>( |
| 31 | fn: T, |
| 32 | ): T { |
| 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 34 | return (async (...args: any[]) => { |
| 35 | try { |
| 36 | return await fn(...args); |
| 37 | } catch (error) { |
| 38 | if (error instanceof OptionValidationError) { |
| 39 | logger.error(error.message); |
| 40 | await new Promise(resolve => process.stdout.write('', resolve)); |
| 41 | yargs().exit(1, error); |
| 42 | } else { |
| 43 | logger.error(stringifyError(error)); |
| 44 | await new Promise(resolve => process.stdout.write('', resolve)); |
| 45 | throw error; |
| 46 | } |
| 47 | } |
| 48 | }) as T; |
| 49 | } |
| 50 | |
| 51 | export function coerceArray(param: string): string[] { |
| 52 | return [...new Set(toArray(param).flatMap(f => f.split(',')))]; |
no test coverage detected