/********************************************************************* * * * 命令装饰器 * 创建时间: 2021-05-31 * 作者: 孟凯伦 * * **********************************************************************/ import { Command } from "commander"; import ICommand from "./iCommand"; // 创建命令行对象 const program = new Command(); /** * 命令装饰器 * @param name 命令名 * @param alias 别名 */ export default function >( name: string, alias?: string ): (target: T) => void { return (target: T): void => { // 实例化装饰类 const instance: ICommand = new target(); let cmdName = name; if (alias !== undefined) { cmdName = `${alias}, ${cmdName}`; }; program.option(cmdName, instance.Description(), () => instance.Action(program)); }; } /** * 启动命令行 */ export function Start(): void { console.log("Component Development Scaffolding"); program.helpOption(false); program.parse(process.argv); }