(
args: string[],
context: CommandContext,
options?: { hasFormats: boolean },
)
| 15 | * @param options Optional information on whether all persist formats are set (if known) |
| 16 | */ |
| 17 | export async function executeCliCommand( |
| 18 | args: string[], |
| 19 | context: CommandContext, |
| 20 | options?: { hasFormats: boolean }, |
| 21 | ): Promise<void> { |
| 22 | const { logOutputChunk, logOutputEnd, logSilencedOutput } = |
| 23 | createLogCallbacks(context); |
| 24 | |
| 25 | const observer: ProcessObserver = { |
| 26 | onStdout: logOutputChunk, |
| 27 | onStderr: logOutputChunk, |
| 28 | onComplete: logOutputEnd, |
| 29 | onError: logOutputEnd, |
| 30 | }; |
| 31 | |
| 32 | const config: ProcessConfig = { |
| 33 | command: context.bin, |
| 34 | args: combineArgs(args, context, options), |
| 35 | cwd: context.directory, |
| 36 | observer, |
| 37 | silent: true, |
| 38 | }; |
| 39 | const bin = serializeCommandWithArgs(config); |
| 40 | |
| 41 | try { |
| 42 | await logger.command(bin, async () => { |
| 43 | try { |
| 44 | await executeProcess(config); |
| 45 | } catch (error) { |
| 46 | // ensure output of failed process is always logged for debugging |
| 47 | logSilencedOutput(); |
| 48 | throw error; |
| 49 | } |
| 50 | }); |
| 51 | } finally { |
| 52 | logger.newline(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | function createLogCallbacks(context: Pick<CommandContext, 'silent'>) { |
| 57 | // eslint-disable-next-line functional/no-let |
no test coverage detected