{"version":3,"file":"CommandManager.cjs","sources":["../../../../../packages/cli-common/src/application/CommandManager.ts"],"sourcesContent":["import { Command } from './Command'\nimport chalk from 'chalk'\n\nexport type CommandFactoryList = { [command: string]: () => Command<any, any> }\n\nexport class CommandManager {\n\tconstructor(public readonly commands: CommandFactoryList) {}\n\n\tpublic createCommand(name: string): [string, Command<any, any>] {\n\t\tconst fullName = this.findCommand(name)\n\t\tconst factory = this.commands[fullName]\n\t\tconst originalCommand = Object.entries(this.commands).find(([, it]) => it === factory)\n\t\tif (!originalCommand) {\n\t\t\tthrow new Error('impl error')\n\t\t}\n\t\tif (originalCommand[0] !== fullName) {\n\t\t\tconsole.warn(chalk.yellow(`Command name \"${fullName}\" is deprecated, use \"${originalCommand[0]}\" instead.`))\n\t\t}\n\t\treturn [fullName, factory()]\n\t}\n\n\tprivate findCommand(name: string): string {\n\t\tif (this.commands[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst pattern = new RegExp('^' + name.replace(/:/g, '\\\\w*\\\\:'))\n\t\tconst matchedCommands = Object.keys(this.commands).filter(it => it.match(pattern))\n\t\tif (matchedCommands.length === 1) {\n\t\t\treturn matchedCommands[0]\n\t\t}\n\t\tif (matchedCommands.length === 0) {\n\t\t\tthrow `Command ${name} not found.`\n\t\t}\n\t\tthrow `Command ${name} is ambiguous. Did you mean one of these?\\n - ` + matchedCommands.join('\\n - ') + '\\n'\n\t}\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,eAAe;AAAA,EAC3B,YAA4B,UAA8B;AAA9B,SAAA,WAAA;AAAA,EAAA;AAAA,EAErB,cAAc,MAA2C;AACzD,UAAA,WAAW,KAAK,YAAY,IAAI;AAChC,UAAA,UAAU,KAAK,SAAS,QAAQ;AACtC,UAAM,kBAAkB,OAAO,QAAQ,KAAK,QAAQ,EAAE,KAAK,CAAC,CAAG,EAAA,EAAE,MAAM,OAAO,OAAO;AACrF,QAAI,CAAC,iBAAiB;AACf,YAAA,IAAI,MAAM,YAAY;AAAA,IAAA;AAEzB,QAAA,gBAAgB,CAAC,MAAM,UAAU;AAC5B,cAAA,KAAK,MAAM,OAAO,iBAAiB,QAAQ,yBAAyB,gBAAgB,CAAC,CAAC,YAAY,CAAC;AAAA,IAAA;AAErG,WAAA,CAAC,UAAU,SAAS;AAAA,EAAA;AAAA,EAGpB,YAAY,MAAsB;AACrC,QAAA,KAAK,SAAS,IAAI,GAAG;AACjB,aAAA;AAAA,IAAA;AAEF,UAAA,UAAU,IAAI,OAAO,MAAM,KAAK,QAAQ,MAAM,SAAS,CAAC;AACxD,UAAA,kBAAkB,OAAO,KAAK,KAAK,QAAQ,EAAE,OAAO,CAAM,OAAA,GAAG,MAAM,OAAO,CAAC;AAC7E,QAAA,gBAAgB,WAAW,GAAG;AACjC,aAAO,gBAAgB,CAAC;AAAA,IAAA;AAErB,QAAA,gBAAgB,WAAW,GAAG;AACjC,YAAM,WAAW,IAAI;AAAA,IAAA;AAEtB,UAAM,WAAW,IAAI;AAAA,OAAmD,gBAAgB,KAAK,OAAO,IAAI;AAAA,EAAA;AAE1G;;"}