import renderHelp from 'render-help' import { getCompletionScript, SUPPORTED_SHELLS } from '@pnpm/tabtab' import { getShellFromParams } from './getShell.js' export const commandNames = ['completion'] export const skipPackageManagerCheck = true export const rcOptionsTypes = (): Record => ({}) export const cliOptionsTypes = (): Record => ({}) export function help (): string { return renderHelp({ description: 'Print shell completion code to stdout', url: 'https://pnpm.io/completion', usages: SUPPORTED_SHELLS.map(shell => `pnpm completion ${shell}`), }) } export interface Context { readonly log: (output: string) => void } export type CompletionGenerator = (_opts: unknown, params: string[]) => Promise export function createCompletionGenerator (ctx: Context): CompletionGenerator { return async function handler (_opts: unknown, params: string[]): Promise { const shell = getShellFromParams(params) const output = await getCompletionScript({ name: 'pnpm', completer: 'pnpm', shell }) ctx.log(output) } } export const handler: CompletionGenerator = createCompletionGenerator({ log: console.log, })