{"version":3,"file":"UsageFormatter.cjs","sources":["../../../../../packages/cli-common/src/application/UsageFormatter.ts"],"sourcesContent":["import { Argument } from './Argument'\nimport { Option, OptionMode } from './Option'\nimport { assertNever } from './assertNever'\n\nexport type UsageFormat = 'line' | 'short' | 'multiline'\nexport type UsageFormatOptions = { format?: UsageFormat; indent?: string }\n\nexport class UsageFormatter {\n\tpublic static format(args: Argument[], options: Option[], { format, indent }: UsageFormatOptions): string {\n\t\tlet parts = []\n\t\tformat ??= 'short'\n\t\tindent ??= '    '\n\t\tconst isShort = format === 'short'\n\t\tfor (let arg of args) {\n\t\t\tconst name = arg.name\n\t\t\tconst argDescription = !isShort && arg.description ? ` (${arg.description})` : ''\n\t\t\tif (arg.variadic) {\n\t\t\t\tparts.push(`[...${name}${argDescription}]`)\n\t\t\t} else if (arg.optional) {\n\t\t\t\tparts.push(`[${name}${argDescription}]`)\n\t\t\t} else {\n\t\t\t\tparts.push(`<${name}${argDescription}>`)\n\t\t\t}\n\t\t}\n\t\tfor (let opt of options) {\n\t\t\tif (opt.deprecated) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst name = `--${opt.name}` + (!isShort && opt.shortcut ? `|-${opt.shortcut}` : '')\n\t\t\tlet valueDescription\n\t\t\tswitch (opt.mode) {\n\t\t\t\tcase OptionMode.VALUE_ARRAY:\n\t\t\t\tcase OptionMode.VALUE_REQUIRED:\n\t\t\t\t\tvalueDescription = ' <value>'\n\t\t\t\t\tbreak\n\t\t\t\tcase OptionMode.VALUE_OPTIONAL:\n\t\t\t\t\tvalueDescription = ' [value]'\n\t\t\t\t\tbreak\n\t\t\t\tcase OptionMode.VALUE_NONE:\n\t\t\t\t\tvalueDescription = ''\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(opt.mode)\n\t\t\t}\n\t\t\tlet optionDescription = `${name}${valueDescription}`\n\t\t\tif (opt.mode === OptionMode.VALUE_ARRAY) {\n\t\t\t\toptionDescription = `${optionDescription} [... ${optionDescription}]`\n\t\t\t}\n\t\t\tif (!isShort && opt.description) {\n\t\t\t\toptionDescription += ` (${opt.description})`\n\t\t\t}\n\t\t\tif (!opt.required) {\n\t\t\t\toptionDescription = `[${optionDescription}]`\n\t\t\t}\n\t\t\tparts.push(optionDescription)\n\t\t}\n\t\tif (format === 'multiline') {\n\t\t\treturn parts.map(it => `${indent}${it}`).join('\\n')\n\t\t}\n\t\treturn parts.join(' ')\n\t}\n}\n"],"names":["OptionMode","assertNever"],"mappings":";;;;AAOO,MAAM,eAAe;AAAA,EAC3B,OAAc,OAAO,MAAkB,SAAmB,EAAE,QAAQ,UAAsC;AACzG,QAAI,QAAQ,CAAC;AACF,eAAA,SAAA;AACA,eAAA,SAAA;AACX,UAAM,UAAU,WAAW;AAC3B,aAAS,OAAO,MAAM;AACrB,YAAM,OAAO,IAAI;AACX,YAAA,iBAAiB,CAAC,WAAW,IAAI,cAAc,KAAK,IAAI,WAAW,MAAM;AAC/E,UAAI,IAAI,UAAU;AACjB,cAAM,KAAK,OAAO,IAAI,GAAG,cAAc,GAAG;AAAA,MAAA,WAChC,IAAI,UAAU;AACxB,cAAM,KAAK,IAAI,IAAI,GAAG,cAAc,GAAG;AAAA,MAAA,OACjC;AACN,cAAM,KAAK,IAAI,IAAI,GAAG,cAAc,GAAG;AAAA,MAAA;AAAA,IACxC;AAED,aAAS,OAAO,SAAS;AACxB,UAAI,IAAI,YAAY;AACnB;AAAA,MAAA;AAED,YAAM,OAAO,KAAK,IAAI,IAAI,MAAM,CAAC,WAAW,IAAI,WAAW,KAAK,IAAI,QAAQ,KAAK;AAC7E,UAAA;AACJ,cAAQ,IAAI,MAAM;AAAA,QACjB,KAAKA,OAAW,WAAA;AAAA,QAChB,KAAKA,OAAW,WAAA;AACI,6BAAA;AACnB;AAAA,QACD,KAAKA,OAAW,WAAA;AACI,6BAAA;AACnB;AAAA,QACD,KAAKA,OAAW,WAAA;AACI,6BAAA;AACnB;AAAA,QACD;AACCC,sBAAA,Y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