| 16 | * functions after the command completes. |
| 17 | */ |
| 18 | export async function runParserWithCompletedFunctions(applyConfiguration: (argv: Argv) => Argv) { |
| 19 | let err: Error | null = null; |
| 20 | try { |
| 21 | await applyConfiguration(yargs(process.argv.slice(2))) |
| 22 | .exitProcess(false) |
| 23 | .parse(); |
| 24 | } catch (e) { |
| 25 | err = e as Error; |
| 26 | if ([undefined, 0].includes(process.exitCode as any)) { |
| 27 | process.exitCode = 1; |
| 28 | } |
| 29 | } finally { |
| 30 | for (const completedFunc of completedFunctions) { |
| 31 | await completedFunc(err); |
| 32 | } |
| 33 | } |
| 34 | } |