(
shell: string,
opts: { output?: string } = {},
program: CommanderCommand,
)
| 873 | } |
| 874 | |
| 875 | export async function completionHandler( |
| 876 | shell: string, |
| 877 | opts: { output?: string } = {}, |
| 878 | program: CommanderCommand, |
| 879 | ): Promise<void> { |
| 880 | try { |
| 881 | const script = generateCompletionScript(shell, program) |
| 882 | if (opts.output) { |
| 883 | const outputPath = expandPath(opts.output) |
| 884 | await mkdir(dirname(outputPath), { recursive: true }) |
| 885 | await writeFile(outputPath, script, 'utf8') |
| 886 | writeToStdout(`Wrote ${shell} completion script to ${outputPath}\n`) |
| 887 | } else { |
| 888 | writeToStdout(script) |
| 889 | if (!script.endsWith('\n')) { |
| 890 | writeToStdout('\n') |
| 891 | } |
| 892 | } |
| 893 | await gracefulShutdown(0) |
| 894 | } catch (error) { |
| 895 | writeToStderr( |
| 896 | `Failed to generate completion script: ${errorMessage(error)}\n`, |
| 897 | ) |
| 898 | await gracefulShutdown(1) |
| 899 | } |
| 900 | } |
no test coverage detected