import process from 'node:process' import { resolve } from 'node:path' import { parseArgs } from 'node:util' import { buildRegistry } from '../registry/build.js' import { parsePackageManager } from '../registry/dependencies.js' import { applyInstallation, describePlan, planInstallation } from '../registry/install.js' import { readRegistryCatalog, resolveRegistryItem } from '../registry/resolve.js' import { emitJson } from '../runtime/json-output.js' import { CLI_VERSION } from '../runtime/version.js' const OPTIONS = { help: { type: 'boolean', short: 'h' }, json: { type: 'boolean' }, config: { type: 'string' }, registry: { type: 'string' }, path: { type: 'string' }, 'dry-run': { type: 'boolean' }, yes: { type: 'boolean', short: 'y' }, 'no-install': { type: 'boolean' }, 'with-tests': { type: 'boolean' }, 'package-manager': { type: 'string' }, output: { type: 'string' }, } as const export async function cmdRegistry(command: 'add' | 'registry', argv: string[]): Promise { const { values, positionals } = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true, strict: true }) if (values.help) { console.log(registryHelp(command)) return } const action = command === 'add' ? 'add' : positionals.shift() const allowed: Record = { add: ['json', 'config', 'registry', 'path', 'dry-run', 'yes', 'no-install', 'with-tests', 'package-manager'], list: ['json', 'registry'], inspect: ['json', 'registry'], build: ['json', 'output'], } if (!action || !allowed[action]) throw new Error('Usage: chkit registry [options]') for (const name of Object.keys(values)) { if (!allowed[action]?.includes(name)) throw new Error(`--${name} is not supported by chkit ${action === 'add' ? 'add' : `registry ${action}`}`) } if (action === 'add') { const reference = onePositional(positionals, 'chkit add