Files
pnpm/completion/plugin-commands-completion/src/generateCompletion.ts
Trevor Burnham 0ecff5b85c fix(completion): correct documentation URL in help output (#10511)
The completion command's help text was showing a URL that redirects to a 404 page
(https://pnpm.io/10.x/cli/completion\). This changes it to the correct URL
(https://pnpm.io/completion\) where the documentation actually exists.

close #10281
2026-01-26 01:30:08 +01:00

38 lines
1.2 KiB
TypeScript

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<string, unknown> => ({})
export const cliOptionsTypes = (): Record<string, unknown> => ({})
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<void>
export function createCompletionGenerator (ctx: Context): CompletionGenerator {
return async function handler (_opts: unknown, params: string[]): Promise<void> {
const shell = getShellFromParams(params)
const output = await getCompletionScript({ name: 'pnpm', completer: 'pnpm', shell })
ctx.log(output)
}
}
export const handler: CompletionGenerator = createCompletionGenerator({
log: console.log,
})