mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-02 03:02:49 -05:00
* feat(completion): generate-completion close #3083 * feat: better error message * test: generate-completion * feat(completion): add powershell * chore(deps): update @pnpm/tabtab to 0.3.0 * switch to provided type declarations * fix typings * update tests * update bundle scripts * refactor: remove unnecessary `??` * refactor: replace a type def with provided types * chore(deps): update @pnpm/tabtab to 0.4.0 * feat(cli): rename completion command * chore(deps): update @pnpm/tabtab to 0.4.1 * refactor: use tabtab's new features * fix: pass shell * chore(deps): update @pnpm/tabtab to 0.5.0 * chore(deps): update @pnpm/tabtab to 0.5.1 * fix: remove unused import * refactor: move completion to plugins * feat: remove `{install,uninstall}-completion` Just `pnpm completion` is enough * test: fix * refactor: direct import * refactor: move tests to next to the lib * refactor: merge 2 packages into 1 * fix: update changeset and remove install-completion
29 lines
823 B
TypeScript
29 lines
823 B
TypeScript
import { PnpmError } from '@pnpm/error'
|
|
import { isShellSupported, SUPPORTED_SHELLS, type SupportedShell } from '@pnpm/tabtab'
|
|
|
|
export function getShellFromString (shell?: string): SupportedShell {
|
|
shell = shell?.trim()
|
|
|
|
if (!shell) {
|
|
throw new PnpmError('MISSING_SHELL_NAME', '`pnpm completion` requires a shell name')
|
|
}
|
|
|
|
if (!isShellSupported(shell)) {
|
|
throw new PnpmError('UNSUPPORTED_SHELL', `'${shell}' is not supported`, {
|
|
hint: `Supported shells are: ${SUPPORTED_SHELLS.join(', ')}`,
|
|
})
|
|
}
|
|
|
|
return shell
|
|
}
|
|
|
|
export function getShellFromParams (params: string[]): SupportedShell {
|
|
const [shell, ...rest] = params
|
|
|
|
if (rest.length) {
|
|
throw new PnpmError('REDUNDANT_PARAMETERS', `The ${rest.length} parameters after shell is not necessary`)
|
|
}
|
|
|
|
return getShellFromString(shell)
|
|
}
|