UNPKG

@tsed/cli-core

Version:
45 lines (44 loc) 1.83 kB
import { isArrowFn, Store } from "@tsed/core"; export function getCommandMetadata(token) { const { name, alias, args = {}, description, options = {}, enableFeatures, disableReadUpPkg, inputSchema, renderMode, ...opts } = Store.from(token)?.get("command"); return { name, inputSchema, alias, description, enableFeatures: enableFeatures || [], disableReadUpPkg: !!disableReadUpPkg, renderMode, ...opts, getOptions() { if (inputSchema) { const schema = isArrowFn(inputSchema) ? inputSchema() : inputSchema; Object.entries(schema.get("properties") || {})?.forEach(([propertyKey, propertySchema]) => { const base = { type: propertySchema.getTarget(), itemType: propertySchema.isCollection ? propertySchema.get("items").getTarget() : undefined, description: propertySchema.get("description") || "", defaultValue: propertySchema.get("default"), required: schema.isRequired(propertyKey) }; const opt = propertySchema.get("x-opt"); if (opt) { options[opt] = { ...base, customParser: schema.get("custom-parser") }; } else { args[propertyKey] = base; } }); opts.allowUnknownOption = !!schema.get("additionalProperties"); } return { args, options, allowUnknownOption: !!opts.allowUnknownOption }; } }; }