zod-args-parser 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/help-message/format-arguments.js +1 -1
- package/lib/commonjs/help-message/format-arguments.js.map +1 -1
- package/lib/commonjs/help-message/format-cli.js +1 -1
- package/lib/commonjs/help-message/format-cli.js.map +1 -1
- package/lib/commonjs/help-message/format-options.js +1 -1
- package/lib/commonjs/help-message/format-options.js.map +1 -1
- package/lib/commonjs/help-message/format-subcommands.js +1 -1
- package/lib/commonjs/help-message/format-subcommands.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/help-message/format-arguments.js +1 -1
- package/lib/module/help-message/format-arguments.js.map +1 -1
- package/lib/module/help-message/format-cli.js +1 -1
- package/lib/module/help-message/format-cli.js.map +1 -1
- package/lib/module/help-message/format-options.js +1 -1
- package/lib/module/help-message/format-options.js.map +1 -1
- package/lib/module/help-message/format-subcommands.js +1 -1
- package/lib/module/help-message/format-subcommands.js.map +1 -1
- package/lib/module/utils.js +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
- package/lib/typescript/utils.d.ts +3 -0
- package/lib/typescript/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/help-message/format-arguments.ts +2 -2
- package/src/help-message/format-cli.ts +5 -5
- package/src/help-message/format-options.ts +2 -2
- package/src/help-message/format-subcommands.ts +3 -4
- package/src/utils.ts +26 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatHelpMsgArguments=formatHelpMsgArguments;var _utils=require("../utils.js");function formatHelpMsgArguments(argsMetadata,c,longest){if(!argsMetadata.length)return"";let msg=c.title(" ARGUMENTS")+(0,_utils.ln)(1);for(const metadata of argsMetadata){const defaultStr=typeof metadata.defaultValue!=="undefined"?`(default: ${metadata.defaultValueAsString})`:"";const spacing=longest+2-metadata.name.length;const normalizeDesc=metadata.description.replace(/\n
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatHelpMsgArguments=formatHelpMsgArguments;var _utils=require("../utils.js");function formatHelpMsgArguments(argsMetadata,c,longest){if(!argsMetadata.length)return"";let msg=c.title(" ARGUMENTS")+(0,_utils.ln)(1);for(const metadata of argsMetadata){const defaultStr=typeof metadata.defaultValue!=="undefined"?`(default: ${metadata.defaultValueAsString})`:"";const spacing=longest+2-metadata.name.length;const normalizeDesc=metadata.description.replace(/\n+/g,"\n"+(0,_utils.indent)(longest+6)+c.punctuation("└"));const defaultOrOptional=defaultStr?c.default(defaultStr):metadata.optional?c.optional("(optional)"):"";msg+=(0,_utils.concat)((0,_utils.indent)(2)+c.argument(metadata.name),(0,_utils.indent)(spacing),(0,_utils.insertAtEndOfFirstLine)(c.description(normalizeDesc),defaultOrOptional),(0,_utils.ln)(1));if(metadata.example){const normalizeExample=metadata.example.replace(/\n+/g,"\n"+(0,_utils.indent)(longest+16));msg+=(0,_utils.concat)((0,_utils.indent)(longest+5),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample)+(0,_utils.ln)(1));}}msg+=(0,_utils.ln)(1);return msg;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_utils","require","formatHelpMsgArguments","argsMetadata","c","longest","length","msg","title","ln","metadata","defaultStr","defaultValue","defaultValueAsString","spacing","name","normalizeDesc","description","replace","indent","punctuation","defaultOrOptional","default","optional","concat","argument","insertAtEndOfFirstLine","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-arguments.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { ArgumentMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgArguments(argsMetadata: ArgumentMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!argsMetadata.length) return \"\";\n\n let msg = c.title(\" ARGUMENTS\") + ln(1);\n\n for (const metadata of argsMetadata) {\n const defaultStr =\n typeof metadata.defaultValue !== \"undefined\" ? `(default: ${metadata.defaultValueAsString})` : \"\";\n\n const spacing = longest + 2 - metadata.name.length;\n const normalizeDesc = metadata.description.replace(/\\n
|
|
1
|
+
{"version":3,"names":["_utils","require","formatHelpMsgArguments","argsMetadata","c","longest","length","msg","title","ln","metadata","defaultStr","defaultValue","defaultValueAsString","spacing","name","normalizeDesc","description","replace","indent","punctuation","defaultOrOptional","default","optional","concat","argument","insertAtEndOfFirstLine","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-arguments.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { ArgumentMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgArguments(argsMetadata: ArgumentMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!argsMetadata.length) return \"\";\n\n let msg = c.title(\" ARGUMENTS\") + ln(1);\n\n for (const metadata of argsMetadata) {\n const defaultStr =\n typeof metadata.defaultValue !== \"undefined\" ? `(default: ${metadata.defaultValueAsString})` : \"\";\n\n const spacing = longest + 2 - metadata.name.length;\n const normalizeDesc = metadata.description.replace(/\\n+/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n const defaultOrOptional = defaultStr ? c.default(defaultStr) : metadata.optional ? c.optional(\"(optional)\") : \"\";\n\n msg += concat(\n indent(2) + c.argument(metadata.name),\n indent(spacing),\n insertAtEndOfFirstLine(c.description(normalizeDesc), defaultOrOptional),\n ln(1),\n );\n\n if (metadata.example) {\n const normalizeExample = metadata.example.replace(/\\n+/g, \"\\n\" + indent(longest + 16));\n msg += concat(\n indent(longest + 5),\n c.punctuation(\"└\") + c.exampleTitle(\"Example:\"),\n c.example(normalizeExample) + ln(1),\n );\n }\n }\n\n ms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N,CAAC,CAED,GAAIC,QAAQ,CAACiB,OAAO,CAAE,CACpB,KAAM,CAAAC,gBAAgB,CAAGlB,QAAQ,CAACiB,OAAO,CAACT,OAAO,CAAC,MAAM,CAAE,IAAI,CAAG,GAAAC,aAAM,EAACd,OAAO,CAAG,EAAE,CAAC,CAAC,CACtFE,GAAG,EAAI,GAAAiB,aAAM,EACX,GAAAL,aAAM,EAACd,OAAO,CAAG,CAAC,CAAC,CACnBD,CAAC,CAACgB,WAAW,CAAC,GAAG,CAAC,CAAGhB,CAAC,CAACyB,YAAY,CAAC,UAAU,CAAC,CAC/CzB,CAAC,CAACuB,OAAO,CAACC,gBAAgB,CAAC,CAAG,GAAAnB,SAAE,EAAC,CAAC,CACpC,CAAC,CACH,CACF,CAEAF,GAAG,EAAI,GAAAE,SAAE,EAAC,CAAC,CAAC,CAEZ,MAAO,CAAAF,GAAG,CACZ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatCliHelpMsg=formatCliHelpMsg;exports.formatSubcommandHelpMsg=formatSubcommandHelpMsg;exports.printCliHelp=printCliHelp;exports.printSubcommandHelp=printSubcommandHelp;var _getCliMetadata=require("../metadata/get-cli-metadata.js");var _utils=require("../utils.js");var _formatArguments=require("./format-arguments.js");var _formatOptions=require("./format-options.js");var _formatSubcommands=require("./format-subcommands.js");var _styles=require("./styles.js");function formatCliHelpMsg(params,style){const c=_styles.helpMsgStyles.default;if(style)Object.assign(c,style);const metadata=(0,_getCliMetadata.getCliMetadata)(params);const formatTitle=title=>c.title(` ${title.toUpperCase()}`);let msg="";const usage=metadata.usage||(0,_utils.concat)(c.punctuation("$"),c.description(metadata.name),metadata.subcommands.length?c.command("[command]"):"",metadata.options.length?c.option("[options]"):"",metadata.arguments.length
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatCliHelpMsg=formatCliHelpMsg;exports.formatSubcommandHelpMsg=formatSubcommandHelpMsg;exports.printCliHelp=printCliHelp;exports.printSubcommandHelp=printSubcommandHelp;var _getCliMetadata=require("../metadata/get-cli-metadata.js");var _utils=require("../utils.js");var _formatArguments=require("./format-arguments.js");var _formatOptions=require("./format-options.js");var _formatSubcommands=require("./format-subcommands.js");var _styles=require("./styles.js");function formatCliHelpMsg(params,style){const c=_styles.helpMsgStyles.default;if(style)Object.assign(c,style);const metadata=(0,_getCliMetadata.getCliMetadata)(params);const formatTitle=title=>c.title(` ${title.toUpperCase()}`);let msg="";const usage=metadata.usage||(0,_utils.concat)(c.punctuation("$"),c.description(metadata.name),metadata.subcommands.length?c.command("[command]"):"",metadata.options.length?c.option("[options]"):"",metadata.arguments.length?c.argument("<arguments>"):"",metadata.allowPositional?c.argument("<positionals>"):"");msg+=formatTitle("Usage")+(0,_utils.ln)(1);msg+=(0,_utils.indent)(2)+usage+(0,_utils.ln)(2);if(metadata.description){msg+=formatTitle("Description")+(0,_utils.ln)(1);msg+=(0,_utils.indent)(2)+c.description(metadata.description)+(0,_utils.ln)(2);}let longest=0;const optionsMetadata=metadata.options;const longestOptionTitle=optionsMetadata.reduce((acc,metadata)=>{const names=metadata.aliasesAsArgs.concat([metadata.nameAsArg]).join(", ");const optLength=names.length+metadata.placeholder.length;return optLength>acc?optLength:acc;},0);if(longestOptionTitle>longest){longest=longestOptionTitle;}const subcommandsMetadata=metadata.subcommands;const longestSubcommandTitle=subcommandsMetadata.reduce((acc,metadata)=>{const names=metadata.aliases.concat([metadata.name]).join(", ");const placeholder=(0,_utils.subcommandPlaceholder)(metadata);const optLength=names.length+placeholder.length;return optLength>acc?optLength:acc;},0);if(longestSubcommandTitle>longest){longest=longestSubcommandTitle;}const argsMetadata=metadata.arguments;const longestArgTitle=argsMetadata.reduce((acc,arg)=>arg.name.length>acc?arg.name.length:acc,0);if(longestArgTitle>longest){longest=longestArgTitle;}msg+=(0,_formatOptions.formatHelpMsgOptions)(optionsMetadata,c,longest);msg+=(0,_formatSubcommands.formatHelpMsgCommands)(subcommandsMetadata,c,longest);msg+=(0,_formatArguments.formatHelpMsgArguments)(argsMetadata,c,longest);if(metadata.example){msg+=formatTitle("Example");msg+=(0,_utils.ln)(1);const normalizeExample=metadata.example.replace(/\n+/g,"\n"+(0,_utils.indent)(3));msg+=(0,_utils.concat)((0,_utils.indent)(2),c.example(normalizeExample),(0,_utils.ln)(2));}return msg;}function formatSubcommandHelpMsg(subcommand,printStyle,cliName=""){const c=_styles.helpMsgStyles.default;if(printStyle)Object.assign(c,printStyle);const usage=subcommand.usage||(0,_utils.concat)(c.punctuation("$"),cliName,c.command(subcommand.name),subcommand.options?.length?c.option("[options]"):"",subcommand.arguments?.length||subcommand.allowPositional?c.argument("<arguments>"):"");const asCli={cliName,usage,...subcommand};return formatCliHelpMsg([asCli],c);}function printCliHelp(params,style){console.log(formatCliHelpMsg(params,style));}function printSubcommandHelp(subcommand,style,cliName=""){console.log(formatSubcommandHelpMsg(subcommand,style,cliName));}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_getCliMetadata","require","_utils","_formatArguments","_formatOptions","_formatSubcommands","_styles","formatCliHelpMsg","params","style","c","helpMsgStyles","default","Object","assign","metadata","getCliMetadata","formatTitle","title","toUpperCase","msg","usage","concat","punctuation","description","name","subcommands","length","command","options","option","arguments","
|
|
1
|
+
{"version":3,"names":["_getCliMetadata","require","_utils","_formatArguments","_formatOptions","_formatSubcommands","_styles","formatCliHelpMsg","params","style","c","helpMsgStyles","default","Object","assign","metadata","getCliMetadata","formatTitle","title","toUpperCase","msg","usage","concat","punctuation","description","name","subcommands","length","command","options","option","arguments","argument","allowPositional","ln","indent","longest","optionsMetadata","longestOptionTitle","reduce","acc","names","aliasesAsArgs","nameAsArg","join","optLength","placeholder","subcommandsMetadata","longestSubcommandTitle","aliases","subcommandPlaceholder","argsMetadata","longestArgTitle","arg","formatHelpMsgOptions","formatHelpMsgCommands","formatHelpMsgArguments","example","normalizeExample","replace","formatSubcommandHelpMsg","subcommand","printStyle","cliName","asCli","printCliHelp","console","log","printSubcommandHelp"],"sourceRoot":"../../../src/help-message","sources":["format-cli.ts"],"sourcesContent":["import { getCliMetadata } from \"../metadata/get-cli-metadata.js\";\nimport { concat, indent, ln, subcommandPlaceholder } from \"../utils.js\";\nimport { formatHelpMsgArguments } from \"./format-arguments.js\";\nimport { formatHelpMsgOptions } from \"./format-options.js\";\nimport { formatHelpMsgCommands } from \"./format-subcommands.js\";\nimport { helpMsgStyles } from \"./styles.js\";\n\nimport type { Cli, HelpMsgStyle, Subcommand } from \"../types.js\";\n\nexport function formatCliHelpMsg(params: readonly [Cli, ...Subcommand[]], style?: Partial<HelpMsgStyle>): string {\n const c = helpMsgStyles.default;\n if (style) Object.assign(c, style);\n\n const metadata = getCliMetadata(params);\n\n const formatTitle = (title: string) => c.title(` ${title.toUpperCase()}`);\n\n let msg = \"\";\n\n // CLI usage\n const usage =\n metadata.usage ||\n concat(\n c.punctuation(\"$\"),\n c.description(metadata.name),\n metadata.subcommands.length ? c.command(\"[command]\") : \"\",\n metadata.options.length ? c.option(\"[options]\") : \"\",\n metadata.arguments.length ? c.argument(\"<arguments>\") : \"\",\n metadata.allowPositional ? c.argument(\"<positionals>\") : \"\",\n );\n msg += formatTitle(\"Usage\") + ln(1);\n msg += indent(2) + usage + ln(2);\n\n // CLI description\n if (metadata.description) {\n msg += formatTitle(\"Description\") + ln(1);\n msg += indent(2) + c.description(metadata.description) + ln(2);\n }\n\n let longest = 0;\n\n // Prepare CLI options\n const optionsMetadata = metadata.options;\n\n const longestOptionTitle = optionsMetadata.reduce((acc, metadata) => {\n const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]).join(\", \");\n const optLength = names.length + metadata.placeholder.length;\n return optLength > acc ? optLength : acc;\n }, 0);\n\n if (longestOptionTitle > longest) {\n longest = longestOptionTitle;\n }\n\n // Prepare CLI commands\n const subcommandsMetadata = metadata.subcommands;\n\n const longestSubcommandTitle = subcommandsMetadata.reduce((acc, metadata) => {\n const names = metadata.aliases.concat([metadata.name]).join(\", \");\n const placeholder = subcommandPlaceholder(metadata);\n const optLength = names.length + placeholder.length;\n return optLength > acc ? optLength : acc;\n }, 0);\n\n if (longestSubcommandTitle > longest) {\n longest = longestSubcommandTitle;\n }\n\n // Prepare CLI arguments\n const argsMetadata = metadata.arguments;\n const longestArgTitle = argsMetadata.reduce((acc, arg) => (arg.name.length > acc ? arg.name.length : acc), 0);\n if (longestArgTitle > longest) {\n longest = longestArgTitle;\n }\n\n // CLI options\n msg += formatHelpMsgOptions(optionsMetadata, c, longest);\n\n // CLI commands\n msg += formatHelpMsgCommands(subcommandsMetadata, c, longest);\n\n // CLI arguments\n msg += formatHelpMsgArguments(argsMetadata, c, longest);\n\n // CLI example\n if (metadata.example) {\n msg += formatTitle(\"Example\");\n msg += ln(1);\n const normalizeExample = metadata.example.replace(/\\n+/g, \"\\n\" + indent(3));\n msg += concat(indent(2), c.example(normalizeExample), ln(2));\n }\n\n return msg;\n}\n\nexport function formatSubcommandHelpMsg(subcommand: Subcommand, printStyle?: Partial<HelpMsgStyle>, cliName = \"\") {\n const c = helpMsgStyles.default;\n if (printStyle) Object.assign(c, printStyle);\n\n const usage =\n subcommand.usage ||\n concat(\n c.punctuation(\"$\"),\n cliName,\n c.command(subcommand.name),\n subcommand.options?.length ? c.option(\"[options]\") : \"\",\n subcommand.arguments?.length || subcommand.allowPositional ? c.argument(\"<arguments>\") : \"\",\n );\n\n const asCli: Cli = { cliName, usage, ...subcommand };\n\n return formatCliHelpMsg([asCli], c);\n}\n\nexport function printCliHelp(params: readonly [Cli, ...Subcommand[]], style?: Partial<HelpMsgStyle>) {\n console.log(formatCliHelpMsg(params, style));\n}\n\nexport function printSubcommandHelp(subcommand: Subcommand, style?: Partial<HelpMsgStyle>, cliName = \"\") {\n console.log(formatSubcommandHelpMsg(subcommand, style, cliName));\n}\n"],"mappings":"0PAAA,IAAAA,eAAA,CAAAC,OAAA,oCACA,IAAAC,MAAA,CAAAD,OAAA,gBACA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E,CACvGG,OAAO,CAACC,GAAG,CAACP,uBAAuB,CAACC,UAAU,CAAEpD,KAAK,CAAEsD,OAAO,CAAC,CAAC,CAClE","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatHelpMsgOptions=formatHelpMsgOptions;var _utils=require("../utils.js");function formatHelpMsgOptions(optionsMetadata,c,longest){if(!optionsMetadata.length)return"";let msg=c.title(" OPTIONS")+(0,_utils.ln)(1);for(const metadata of optionsMetadata){const names=metadata.aliasesAsArgs.concat([metadata.nameAsArg]);const normalizeDesc=metadata.description.replace(/\n
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatHelpMsgOptions=formatHelpMsgOptions;var _utils=require("../utils.js");function formatHelpMsgOptions(optionsMetadata,c,longest){if(!optionsMetadata.length)return"";let msg=c.title(" OPTIONS")+(0,_utils.ln)(1);for(const metadata of optionsMetadata){const names=metadata.aliasesAsArgs.concat([metadata.nameAsArg]);const normalizeDesc=metadata.description.replace(/\n+/g,"\n"+(0,_utils.indent)(longest+6)+c.punctuation("└"));const defaultStr=typeof metadata.defaultValue!=="undefined"?`(default: ${metadata.defaultValueAsString})`:"";const optLength=names.join(", ").length+metadata.placeholder.length;const spacing=longest+1-optLength;const coloredNames=names.map(name=>c.option(name)).join(c.punctuation(", "));const defaultOrOptional=defaultStr?c.default(defaultStr):metadata.optional?c.optional("(optional)"):"";msg+=(0,_utils.concat)((0,_utils.indent)(2)+coloredNames,c.placeholder(metadata.placeholder),(0,_utils.indent)(spacing),(0,_utils.insertAtEndOfFirstLine)(c.description(normalizeDesc),defaultOrOptional),(0,_utils.ln)(1));if(metadata.example){const normalizeExample=metadata.example.replace(/\n+/g,"\n"+(0,_utils.indent)(longest+16));msg+=(0,_utils.concat)((0,_utils.indent)(longest+6)+c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample)+(0,_utils.ln)(1));}}msg+=(0,_utils.ln)(1);return msg;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_utils","require","formatHelpMsgOptions","optionsMetadata","c","longest","length","msg","title","ln","metadata","names","aliasesAsArgs","concat","nameAsArg","normalizeDesc","description","replace","indent","punctuation","defaultStr","defaultValue","defaultValueAsString","optLength","join","placeholder","spacing","coloredNames","map","name","option","defaultOrOptional","default","optional","insertAtEndOfFirstLine","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-options.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { OptionMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgOptions(optionsMetadata: OptionMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!optionsMetadata.length) return \"\";\n\n let msg = c.title(\" OPTIONS\") + ln(1);\n\n for (const metadata of optionsMetadata) {\n const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]);\n const normalizeDesc = metadata.description.replace(/\\n
|
|
1
|
+
{"version":3,"names":["_utils","require","formatHelpMsgOptions","optionsMetadata","c","longest","length","msg","title","ln","metadata","names","aliasesAsArgs","concat","nameAsArg","normalizeDesc","description","replace","indent","punctuation","defaultStr","defaultValue","defaultValueAsString","optLength","join","placeholder","spacing","coloredNames","map","name","option","defaultOrOptional","default","optional","insertAtEndOfFirstLine","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-options.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { OptionMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgOptions(optionsMetadata: OptionMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!optionsMetadata.length) return \"\";\n\n let msg = c.title(\" OPTIONS\") + ln(1);\n\n for (const metadata of optionsMetadata) {\n const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]);\n const normalizeDesc = metadata.description.replace(/\\n+/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n const defaultStr =\n typeof metadata.defaultValue !== \"undefined\" ? `(default: ${metadata.defaultValueAsString})` : \"\";\n\n const optLength = names.join(\", \").length + metadata.placeholder.length;\n const spacing = longest + 1 - optLength;\n\n const coloredNames = names.map(name => c.option(name)).join(c.punctuation(\", \"));\n\n const defaultOrOptional = defaultStr ? c.default(defaultStr) : metadata.optional ? c.optional(\"(optional)\") : \"\";\n\n msg += concat(\n indent(2) + coloredNames,\n c.placeholder(metadata.placeholder),\n indent(spacing),\n insertAtEndOfFirstLine(c.description(normalizeDesc), defaultOrOptional),\n ln(1),\n );\n\n if (metadata.example) {\n const normalizeExample = metadata.example.replace(/\\n+/g, \"\\n\" + indent(longest + 16));\n msg += concat(\n indent(longest + 6) + c.punctuation(\"└\") + c.exampleTitle(\"Example:\"),\n c.example(normalizeExample) + ln(1),\n );\n }\n }\n\n msg += ln(1);\n\n return msg;\n}\n"],"mappings":"wHAAA,IAAAA,MAAA,CAAAC,OAAA,gBAKO,QAAS,CAAAC,oBAAoBA,CAACC,eAAiC,CAAEC,CAAe,CAAEC,OAAe,CAAU,CAChH,GAAI,CAACF,eAAe,CAACG,MAAM,CAAE,MAAO,EAAE,CAEtC,GAAI,CAAAC,GAAG,CAAGH,CAAC,CAACI,KAAK,CAAC,UAAU,CAAC,CAAG,GAAAC,SAAE,EAAC,CAAC,CAAC,CAErC,IAAK,KAAM,CAAAC,QAAQ,GAAI,CAAAP,eAAe,CAAE,CACtC,KAAM,CAAAQ,KAAK,CAAGD,QAAQ,CAACE,aAAa,CAACC,MAAM,CAAC,CAACH,QAAQ,CAACI,SAAS,CAAC,CAAC,CACjE,KAAM,CAAAC,aAAa,CAAGL,QAAQ,CAACM,WAAW,CAACC,OAAO,CAAC,MAAM,CAAE,IAAI,CAAG,GAAAC,aAAM,EAACb,OAAO,CAAG,CAAC,CAAC,CAAGD,CAAC,C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AI,GAAAM,aAAM,EACX,GAAAK,aAAM,EAACb,OAAO,CAAG,CAAC,CAAC,CAAGD,CAAC,CAACe,WAAW,CAAC,GAAG,CAAC,CAAGf,CAAC,CAACiC,YAAY,CAAC,UAAU,CAAC,CACrEjC,CAAC,CAAC+B,OAAO,CAACC,gBAAgB,CAAC,CAAG,GAAA3B,SAAE,EAAC,CAAC,CACpC,CAAC,CACH,CACF,CAEAF,GAAG,EAAI,GAAAE,SAAE,EAAC,CAAC,CAAC,CAEZ,MAAO,CAAAF,GAAG,CACZ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatHelpMsgCommands=formatHelpMsgCommands;var _utils=require("../utils.js");function formatHelpMsgCommands(subcommandsMetadata,c,longest){if(!subcommandsMetadata.length)return"";let msg=c.title(" COMMANDS")+(0,_utils.ln)(1);for(const metadata of subcommandsMetadata){const names=metadata.aliases.concat([metadata.name]);const placeholder=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatHelpMsgCommands=formatHelpMsgCommands;var _utils=require("../utils.js");function formatHelpMsgCommands(subcommandsMetadata,c,longest){if(!subcommandsMetadata.length)return"";let msg=c.title(" COMMANDS")+(0,_utils.ln)(1);for(const metadata of subcommandsMetadata){const names=metadata.aliases.concat([metadata.name]);const placeholder=(0,_utils.subcommandPlaceholder)(metadata);const normalizeDesc=metadata.description.replace(/\n+/g,"\n"+(0,_utils.indent)(longest+6)+c.punctuation("└"));const optLength=names.join(", ").length+placeholder.length;const spacing=longest+1-optLength;const coloredNames=names.map(name=>c.command(name)).join(c.punctuation(", "));msg+=(0,_utils.concat)((0,_utils.indent)(2)+coloredNames,c.placeholder(placeholder),(0,_utils.indent)(spacing),c.description(normalizeDesc)+(0,_utils.ln)(1));}msg+=(0,_utils.ln)(1);return msg;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_utils","require","formatHelpMsgCommands","subcommandsMetadata","c","longest","length","msg","title","ln","metadata","names","aliases","concat","name","placeholder","
|
|
1
|
+
{"version":3,"names":["_utils","require","formatHelpMsgCommands","subcommandsMetadata","c","longest","length","msg","title","ln","metadata","names","aliases","concat","name","placeholder","subcommandPlaceholder","normalizeDesc","description","replace","indent","punctuation","optLength","join","spacing","coloredNames","map","command"],"sourceRoot":"../../../src/help-message","sources":["format-subcommands.ts"],"sourcesContent":["import { concat, indent, ln, subcommandPlaceholder } from \"../utils.js\";\n\nimport type { SubcommandMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgCommands(\n subcommandsMetadata: SubcommandMetadata[],\n c: HelpMsgStyle,\n longest: number,\n): string {\n if (!subcommandsMetadata.length) return \"\";\n\n let msg = c.title(\" COMMANDS\") + ln(1);\n\n for (const metadata of subcommandsMetadata) {\n const names = metadata.aliases.concat([metadata.name]);\n const placeholder = subcommandPlaceholder(metadata);\n const normalizeDesc = metadata.description.replace(/\\n+/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n\n const optLength = names.join(\", \").length + placeholder.length;\n const spacing = longest + 1 - optLength;\n\n const coloredNames = names.map(name => c.command(name)).join(c.punctuation(\", \"));\n\n msg += concat(\n indent(2) + coloredNames,\n c.placeholder(placeholder),\n indent(spacing),\n c.description(normalizeDesc) + ln(1),\n );\n }\n\n msg += ln(1);\n\n return msg;\n}\n"],"mappings":"0HAAA,IAAAA,MAAA,CAAAC,OAAA,gBAKO,QAAS,CAAAC,qBAAqBA,CACnCC,mBAAyC,CACzCC,CAAe,CACfC,OAAe,CACP,CACR,GAAI,CAACF,mBAAmB,CAACG,MAAM,CAAE,MAAO,EAAE,CAE1C,GAAI,CAAAC,GAAG,CAAGH,CAAC,CAACI,KAAK,CAAC,WAAW,CAAC,CAAG,GAAAC,SAAE,EAAC,CAAC,CAAC,CAEtC,IAAK,KAAM,CAAAC,QAAQ,GAAI,CAAAP,mBAAmB,CAAE,CAC1C,KAAM,CAAAQ,KAAK,CAAGD,QAAQ,CAACE,OAAO,CAACC,MAAM,CAAC,CAACH,QAAQ,CAACI,IAAI,CAAC,CAAC,CACtD,KAAM,CAAAC,WAAW,CAAG,GAAAC,4BAAqB,EAACN,QAAQ,CAAC,CACnD,KAAM,CAAAO,aAAa,CAAGP,QAAQ,CAACQ,WAAW,CAACC,OAAO,CAAC,MAAM,CAAE,IAAI,CAAG,GAAAC,aAAM,EAACf,OAAO,CAAG,CAAC,CAAC,CAAGD,CAAC,CAACiB,WAAW,CAAC,GAAG,CAAC,CAAC,CAE3G,KAAM,CAAAC,SAAS,CAAGX,KAAK,CAACY,IAAI,CAAC,IAAI,CAAC,CAACjB,MAAM,CAAGS,WAAW,CAACT,MAAM,CAC9D,KAAM,CAAAkB,OAAO,CAAGnB,OAAO,CAAG,CAAC,CAAGiB,SAAS,CAEvC,KAAM,CAAAG,YAAY,CAAGd,KAAK,CAACe,GAAG,CAACZ,IAAI,EAAIV,CAAC,CAACuB,OAAO,CAACb,IAAI,CAAC,CAAC,CAACS,IAAI,CAACnB,CAAC,CAACiB,WAAW,CAAC,IAAI,CAAC,CAAC,CAEjFd,GAAG,EAAI,GAAAM,aAAM,EACX,GAAAO,aAAM,EAAC,CAAC,CAAC,CAAGK,YAAY,CACxBrB,CAAC,CAACW,WAAW,CAACA,WAAW,CAAC,CAC1B,GAAAK,aAAM,EAACI,OAAO,CAAC,CACfpB,CAAC,CAACc,WAAW,CAACD,aAAa,CAAC,CAAG,GAAAR,SAAE,EAAC,CAAC,CACrC,CAAC,CACH,CAEAF,GAAG,EAAI,GAAAE,SAAE,EAAC,CAAC,CAAC,CAEZ,MAAO,CAAAF,GAAG,CACZ","ignoreList":[]}
|
package/lib/commonjs/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.concat=concat;exports.generateOrdinalSuffix=generateOrdinalSuffix;exports.indent=indent;exports.insertAtEndOfFirstLine=insertAtEndOfFirstLine;exports.ln=ln;exports.stringToBoolean=stringToBoolean;exports.stringifyValue=stringifyValue;function stringToBoolean(str){if(str.toLowerCase()==="true"){return true;}if(str.toLowerCase()==="false"){return false;}return str;}function generateOrdinalSuffix(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}function ln(count){return"\n".repeat(count);}function indent(count){return" ".repeat(count);}function concat(...messages){return messages.join(" ");}function stringifyValue(value){if(value instanceof Set){return"new Set(["+Array.from(value).map(stringifyValue).join(", ")+"])";}return JSON.stringify(value);}function insertAtEndOfFirstLine(str,insert){const lines=str.split("\n");lines[0]+=" "+insert;return lines.join("\n");}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.concat=concat;exports.generateOrdinalSuffix=generateOrdinalSuffix;exports.indent=indent;exports.insertAtEndOfFirstLine=insertAtEndOfFirstLine;exports.ln=ln;exports.stringToBoolean=stringToBoolean;exports.stringifyValue=stringifyValue;exports.subcommandPlaceholder=subcommandPlaceholder;function stringToBoolean(str){if(str.toLowerCase()==="true"){return true;}if(str.toLowerCase()==="false"){return false;}return str;}function generateOrdinalSuffix(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}function ln(count){return"\n".repeat(count);}function indent(count){if(count<=0)return"";return" ".repeat(count);}function concat(...messages){return messages.join(" ");}function stringifyValue(value){if(value instanceof Set){return"new Set(["+Array.from(value).map(stringifyValue).join(", ")+"])";}return JSON.stringify(value);}function insertAtEndOfFirstLine(str,insert){const lines=str.split("\n");lines[0]+=" "+insert;return lines.join("\n");}function subcommandPlaceholder(metadata){let placeholder=metadata.placeholder;if(!placeholder&&metadata.options.length){placeholder="[options]";}if(!placeholder&&metadata.arguments.length){placeholder="<arguments>";}if(metadata.allowPositional){placeholder+=(placeholder?" ":"")+"<positionals>";}if(!placeholder){placeholder=" ";}return placeholder;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["stringToBoolean","str","toLowerCase","generateOrdinalSuffix","index","suffixes","lastDigit","lastTwoDigits","suffix","ln","count","repeat","indent","concat","messages","join","stringifyValue","value","Set","Array","from","map","JSON","stringify","insertAtEndOfFirstLine","insert","lines","split"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["/**\n * Converts a string to its corresponding boolean value if the string is \"true\" or \"false\" (case-insensitive).\n *\n * @param str - The input string to convert.\n * @returns `true` if the input is \"true\", `false` if the input is \"false\", or the original string otherwise.\n */\nexport function stringToBoolean(str: string): boolean | string {\n if (str.toLowerCase() === \"true\") {\n return true;\n }\n\n if (str.toLowerCase() === \"false\") {\n return false;\n }\n\n return str;\n}\n\n/**\n * Returns the ordinal representation of a given zero-based index.\n *\n * For example, passing `0` returns `\"1st\"`, `1` returns `\"2nd\"`, and so on.\n *\n * Handles special cases for numbers ending in 11, 12, or 13 (e.g., `10` returns `\"11th\"`).\n *\n * @param index - The zero-based index to convert to an ordinal string.\n * @returns The ordinal string representation (e.g., `\"1st\"`, `\"2nd\"`, `\"3rd\"`, `\"4th\"`, ...).\n */\nexport function generateOrdinalSuffix(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** New line */\nexport function ln(count: number) {\n return \"\\n\".repeat(count);\n}\n\n/** Space */\nexport function indent(count: number) {\n return \" \".repeat(count);\n}\n\n/** Concat strings */\nexport function concat(...messages: string[]) {\n // messages = messages.filter(Boolean);\n return messages.join(\" \");\n}\n\nexport function stringifyValue(value: unknown): string {\n // Set\n if (value instanceof Set) {\n return \"new Set([\" + Array.from(value).map(stringifyValue).join(\", \") + \"])\";\n }\n\n // unknown\n return JSON.stringify(value);\n}\n\n/** Insert text at the end of the first line */\nexport function insertAtEndOfFirstLine(str: string, insert: string) {\n const lines = str.split(\"\\n\");\n lines[0] += \" \" + insert;\n return lines.join(\"\\n\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["stringToBoolean","str","toLowerCase","generateOrdinalSuffix","index","suffixes","lastDigit","lastTwoDigits","suffix","ln","count","repeat","indent","concat","messages","join","stringifyValue","value","Set","Array","from","map","JSON","stringify","insertAtEndOfFirstLine","insert","lines","split","subcommandPlaceholder","metadata","placeholder","options","length","arguments","allowPositional"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import { SubcommandMetadata } from \"./metadata/metadata-types.js\";\n\n/**\n * Converts a string to its corresponding boolean value if the string is \"true\" or \"false\" (case-insensitive).\n *\n * @param str - The input string to convert.\n * @returns `true` if the input is \"true\", `false` if the input is \"false\", or the original string otherwise.\n */\nexport function stringToBoolean(str: string): boolean | string {\n if (str.toLowerCase() === \"true\") {\n return true;\n }\n\n if (str.toLowerCase() === \"false\") {\n return false;\n }\n\n return str;\n}\n\n/**\n * Returns the ordinal representation of a given zero-based index.\n *\n * For example, passing `0` returns `\"1st\"`, `1` returns `\"2nd\"`, and so on.\n *\n * Handles special cases for numbers ending in 11, 12, or 13 (e.g., `10` returns `\"11th\"`).\n *\n * @param index - The zero-based index to convert to an ordinal string.\n * @returns The ordinal string representation (e.g., `\"1st\"`, `\"2nd\"`, `\"3rd\"`, `\"4th\"`, ...).\n */\nexport function generateOrdinalSuffix(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** New line */\nexport function ln(count: number) {\n return \"\\n\".repeat(count);\n}\n\n/** Space */\nexport function indent(count: number) {\n if (count <= 0) return \"\";\n return \" \".repeat(count);\n}\n\n/** Concat strings */\nexport function concat(...messages: string[]) {\n // messages = messages.filter(Boolean);\n return messages.join(\" \");\n}\n\nexport function stringifyValue(value: unknown): string {\n // Set\n if (value instanceof Set) {\n return \"new Set([\" + Array.from(value).map(stringifyValue).join(\", \") + \"])\";\n }\n\n // unknown\n return JSON.stringify(value);\n}\n\n/** Insert text at the end of the first line */\nexport function insertAtEndOfFirstLine(str: string, insert: string) {\n const lines = str.split(\"\\n\");\n lines[0] += \" \" + insert;\n return lines.join(\"\\n\");\n}\n\n/** Get the placeholder for a subcommand */\nexport function subcommandPlaceholder(metadata: SubcommandMetadata): string {\n let placeholder = metadata.placeholder;\n\n if (!placeholder && metadata.options.length) {\n placeholder = \"[options]\";\n }\n\n if (!placeholder && metadata.arguments.length) {\n placeholder = \"<arguments>\";\n }\n\n if (metadata.allowPositional) {\n placeholder += (placeholder ? \" \" : \"\") + \"<positionals>\";\n }\n\n if (!placeholder) {\n placeholder = \" \";\n }\n\n return placeholder;\n}\n"],"mappings":"4WAQO,QAAS,CAAAA,eAAeA,CAACC,GAAW,CAAoB,CAC7D,GAAIA,GAAG,CAACC,WAAW,CAAC,CAAC,GAAK,MAAM,CAAE,CAChC,MAAO,KAAI,CACb,CAEA,GAAID,GAAG,CAACC,WAAW,CAAC,CAAC,GAAK,O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C,CAACI,GAAG,CAACL,cAAc,CAAC,CAACD,IAAI,CAAC,IAAI,CAAC,CAAG,IAAI,CAC9E,CAGA,MAAO,CAAAO,IAAI,CAACC,SAAS,CAACN,KAAK,CAAC,CAC9B,CAGO,QAAS,CAAAO,sBAAsBA,CAACvB,GAAW,CAAEwB,MAAc,CAAE,CAClE,KAAM,CAAAC,KAAK,CAAGzB,GAAG,CAAC0B,KAAK,CAAC,IAAI,CAAC,CAC7BD,KAAK,CAAC,CAAC,CAAC,EAAI,GAAG,CAAGD,MAAM,CACxB,MAAO,CAAAC,KAAK,CAACX,IAAI,CAAC,IAAI,CAAC,CACzB,CAGO,QAAS,CAAAa,qBAAqBA,CAACC,QAA4B,CAAU,CAC1E,GAAI,CAAAC,WAAW,CAAGD,QAAQ,CAACC,WAAW,CAEtC,GAAI,CAACA,WAAW,EAAID,QAAQ,CAACE,OAAO,CAACC,MAAM,CAAE,CAC3CF,WAAW,CAAG,WAAW,CAC3B,CAEA,GAAI,CAACA,WAAW,EAAID,QAAQ,CAACI,SAAS,CAACD,MAAM,CAAE,CAC7CF,WAAW,CAAG,aAAa,CAC7B,CAEA,GAAID,QAAQ,CAACK,eAAe,CAAE,CAC5BJ,WAAW,EAAI,CAACA,WAAW,CAAG,GAAG,CAAG,EAAE,EAAI,eAAe,CAC3D,CAEA,GAAI,CAACA,WAAW,CAAE,CAChBA,WAAW,CAAG,GAAG,CACnB,CAEA,MAAO,CAAAA,WAAW,CACpB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{concat,indent,insertAtEndOfFirstLine,ln}from"../utils.js";export function formatHelpMsgArguments(argsMetadata,c,longest){if(!argsMetadata.length)return"";let msg=c.title(" ARGUMENTS")+ln(1);for(const metadata of argsMetadata){const defaultStr=typeof metadata.defaultValue!=="undefined"?`(default: ${metadata.defaultValueAsString})`:"";const spacing=longest+2-metadata.name.length;const normalizeDesc=metadata.description.replace(/\n
|
|
1
|
+
import{concat,indent,insertAtEndOfFirstLine,ln}from"../utils.js";export function formatHelpMsgArguments(argsMetadata,c,longest){if(!argsMetadata.length)return"";let msg=c.title(" ARGUMENTS")+ln(1);for(const metadata of argsMetadata){const defaultStr=typeof metadata.defaultValue!=="undefined"?`(default: ${metadata.defaultValueAsString})`:"";const spacing=longest+2-metadata.name.length;const normalizeDesc=metadata.description.replace(/\n+/g,"\n"+indent(longest+6)+c.punctuation("└"));const defaultOrOptional=defaultStr?c.default(defaultStr):metadata.optional?c.optional("(optional)"):"";msg+=concat(indent(2)+c.argument(metadata.name),indent(spacing),insertAtEndOfFirstLine(c.description(normalizeDesc),defaultOrOptional),ln(1));if(metadata.example){const normalizeExample=metadata.example.replace(/\n+/g,"\n"+indent(longest+16));msg+=concat(indent(longest+5),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample)+ln(1));}}msg+=ln(1);return msg;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["concat","indent","insertAtEndOfFirstLine","ln","formatHelpMsgArguments","argsMetadata","c","longest","length","msg","title","metadata","defaultStr","defaultValue","defaultValueAsString","spacing","name","normalizeDesc","description","replace","punctuation","defaultOrOptional","default","optional","argument","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-arguments.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { ArgumentMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgArguments(argsMetadata: ArgumentMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!argsMetadata.length) return \"\";\n\n let msg = c.title(\" ARGUMENTS\") + ln(1);\n\n for (const metadata of argsMetadata) {\n const defaultStr =\n typeof metadata.defaultValue !== \"undefined\" ? `(default: ${metadata.defaultValueAsString})` : \"\";\n\n const spacing = longest + 2 - metadata.name.length;\n const normalizeDesc = metadata.description.replace(/\\n
|
|
1
|
+
{"version":3,"names":["concat","indent","insertAtEndOfFirstLine","ln","formatHelpMsgArguments","argsMetadata","c","longest","length","msg","title","metadata","defaultStr","defaultValue","defaultValueAsString","spacing","name","normalizeDesc","description","replace","punctuation","defaultOrOptional","default","optional","argument","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-arguments.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { ArgumentMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgArguments(argsMetadata: ArgumentMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!argsMetadata.length) return \"\";\n\n let msg = c.title(\" ARGUMENTS\") + ln(1);\n\n for (const metadata of argsMetadata) {\n const defaultStr =\n typeof metadata.defaultValue !== \"undefined\" ? `(default: ${metadata.defaultValueAsString})` : \"\";\n\n const spacing = longest + 2 - metadata.name.length;\n const normalizeDesc = metadata.description.replace(/\\n+/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n const defaultOrOptional = defaultStr ? c.default(defaultStr) : metadata.optional ? c.optional(\"(optional)\") : \"\";\n\n msg += concat(\n indent(2) + c.argument(metadata.name),\n indent(spacing),\n insertAtEndOfFirstLine(c.description(normalizeDesc), defaultOrOptional),\n ln(1),\n );\n\n if (metadata.example) {\n const normalizeExample = metadata.example.replace(/\\n+/g, \"\\n\" + indent(longest + 16));\n msg += concat(\n indent(longest + 5),\n c.punctuation(\"└\") + c.exampleTitle(\"Example:\"),\n c.example(normalizeExample) + ln(1),\n );\n }\n }\n\n msg += ln(1);\n\n return msg;\n}\n"],"mappings":"AAAA,OAASA,MAAM,CAAEC,MAAM,CAAEC,sBAAsB,CAAEC,EAAE,KAAQ,aAAa,CAKxE,MAAO,SAAS,CAAAC,sBAAsBA,CAACC,YAAgC,CAAEC,CAAe,CAAEC,OAAe,CAAU,CACjH,GAAI,CAACF,YAAY,CAACG,MAAM,CAAE,MAAO,EAAE,CAEnC,GAAI,CAAAC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CAAC,CAACc,WAAW,CAAC,GAAG,CAAC,CAAGd,CAAC,CAACqB,YAAY,CAAC,UAAU,CAAC,CAC/CrB,CAAC,CAACmB,OAAO,CAACC,gBAAgB,CAAC,CAAGvB,EAAE,CAAC,CAAC,CACpC,CAAC,CACH,CACF,CAEAM,GAAG,EAAIN,EAAE,CAAC,CAAC,CAAC,CAEZ,MAAO,CAAAM,GAAG,CACZ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getCliMetadata}from"../metadata/get-cli-metadata.js";import{concat,indent,ln}from"../utils.js";import{formatHelpMsgArguments}from"./format-arguments.js";import{formatHelpMsgOptions}from"./format-options.js";import{formatHelpMsgCommands}from"./format-subcommands.js";import{helpMsgStyles}from"./styles.js";export function formatCliHelpMsg(params,style){const c=helpMsgStyles.default;if(style)Object.assign(c,style);const metadata=getCliMetadata(params);const formatTitle=title=>c.title(` ${title.toUpperCase()}`);let msg="";const usage=metadata.usage||concat(c.punctuation("$"),c.description(metadata.name),metadata.subcommands.length?c.command("[command]"):"",metadata.options.length?c.option("[options]"):"",metadata.arguments.length
|
|
1
|
+
import{getCliMetadata}from"../metadata/get-cli-metadata.js";import{concat,indent,ln,subcommandPlaceholder}from"../utils.js";import{formatHelpMsgArguments}from"./format-arguments.js";import{formatHelpMsgOptions}from"./format-options.js";import{formatHelpMsgCommands}from"./format-subcommands.js";import{helpMsgStyles}from"./styles.js";export function formatCliHelpMsg(params,style){const c=helpMsgStyles.default;if(style)Object.assign(c,style);const metadata=getCliMetadata(params);const formatTitle=title=>c.title(` ${title.toUpperCase()}`);let msg="";const usage=metadata.usage||concat(c.punctuation("$"),c.description(metadata.name),metadata.subcommands.length?c.command("[command]"):"",metadata.options.length?c.option("[options]"):"",metadata.arguments.length?c.argument("<arguments>"):"",metadata.allowPositional?c.argument("<positionals>"):"");msg+=formatTitle("Usage")+ln(1);msg+=indent(2)+usage+ln(2);if(metadata.description){msg+=formatTitle("Description")+ln(1);msg+=indent(2)+c.description(metadata.description)+ln(2);}let longest=0;const optionsMetadata=metadata.options;const longestOptionTitle=optionsMetadata.reduce((acc,metadata)=>{const names=metadata.aliasesAsArgs.concat([metadata.nameAsArg]).join(", ");const optLength=names.length+metadata.placeholder.length;return optLength>acc?optLength:acc;},0);if(longestOptionTitle>longest){longest=longestOptionTitle;}const subcommandsMetadata=metadata.subcommands;const longestSubcommandTitle=subcommandsMetadata.reduce((acc,metadata)=>{const names=metadata.aliases.concat([metadata.name]).join(", ");const placeholder=subcommandPlaceholder(metadata);const optLength=names.length+placeholder.length;return optLength>acc?optLength:acc;},0);if(longestSubcommandTitle>longest){longest=longestSubcommandTitle;}const argsMetadata=metadata.arguments;const longestArgTitle=argsMetadata.reduce((acc,arg)=>arg.name.length>acc?arg.name.length:acc,0);if(longestArgTitle>longest){longest=longestArgTitle;}msg+=formatHelpMsgOptions(optionsMetadata,c,longest);msg+=formatHelpMsgCommands(subcommandsMetadata,c,longest);msg+=formatHelpMsgArguments(argsMetadata,c,longest);if(metadata.example){msg+=formatTitle("Example");msg+=ln(1);const normalizeExample=metadata.example.replace(/\n+/g,"\n"+indent(3));msg+=concat(indent(2),c.example(normalizeExample),ln(2));}return msg;}export function formatSubcommandHelpMsg(subcommand,printStyle,cliName=""){const c=helpMsgStyles.default;if(printStyle)Object.assign(c,printStyle);const usage=subcommand.usage||concat(c.punctuation("$"),cliName,c.command(subcommand.name),subcommand.options?.length?c.option("[options]"):"",subcommand.arguments?.length||subcommand.allowPositional?c.argument("<arguments>"):"");const asCli={cliName,usage,...subcommand};return formatCliHelpMsg([asCli],c);}export function printCliHelp(params,style){console.log(formatCliHelpMsg(params,style));}export function printSubcommandHelp(subcommand,style,cliName=""){console.log(formatSubcommandHelpMsg(subcommand,style,cliName));}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getCliMetadata","concat","indent","ln","formatHelpMsgArguments","formatHelpMsgOptions","formatHelpMsgCommands","helpMsgStyles","formatCliHelpMsg","params","style","c","default","Object","assign","metadata","formatTitle","title","toUpperCase","msg","usage","punctuation","description","name","subcommands","length","command","options","option","arguments","
|
|
1
|
+
{"version":3,"names":["getCliMetadata","concat","indent","ln","subcommandPlaceholder","formatHelpMsgArguments","formatHelpMsgOptions","formatHelpMsgCommands","helpMsgStyles","formatCliHelpMsg","params","style","c","default","Object","assign","metadata","formatTitle","title","toUpperCase","msg","usage","punctuation","description","name","subcommands","length","command","options","option","arguments","argument","allowPositional","longest","optionsMetadata","longestOptionTitle","reduce","acc","names","aliasesAsArgs","nameAsArg","join","optLength","placeholder","subcommandsMetadata","longestSubcommandTitle","aliases","argsMetadata","longestArgTitle","arg","example","normalizeExample","replace","formatSubcommandHelpMsg","subcommand","printStyle","cliName","asCli","printCliHelp","console","log","printSubcommandHelp"],"sourceRoot":"../../../src/help-message","sources":["format-cli.ts"],"sourcesContent":["import { getCliMetadata } from \"../metadata/get-cli-metadata.js\";\nimport { concat, indent, ln, subcommandPlaceholder } from \"../utils.js\";\nimport { formatHelpMsgArguments } from \"./format-arguments.js\";\nimport { formatHelpMsgOptions } from \"./format-options.js\";\nimport { formatHelpMsgCommands } from \"./format-subcommands.js\";\nimport { helpMsgStyles } from \"./styles.js\";\n\nimport type { Cli, HelpMsgStyle, Subcommand } from \"../types.js\";\n\nexport function formatCliHelpMsg(params: readonly [Cli, ...Subcommand[]], style?: Partial<HelpMsgStyle>): string {\n const c = helpMsgStyles.default;\n if (style) Object.assign(c, style);\n\n const metadata = getCliMetadata(params);\n\n const formatTitle = (title: string) => c.title(` ${title.toUpperCase()}`);\n\n let msg = \"\";\n\n // CLI usage\n const usage =\n metadata.usage ||\n concat(\n c.punctuation(\"$\"),\n c.description(metadata.name),\n metadata.subcommands.length ? c.command(\"[command]\") : \"\",\n metadata.options.length ? c.option(\"[options]\") : \"\",\n metadata.arguments.length ? c.argument(\"<arguments>\") : \"\",\n metadata.allowPositional ? c.argument(\"<positionals>\") : \"\",\n );\n msg += formatTitle(\"Usage\") + ln(1);\n msg += indent(2) + usage + ln(2);\n\n // CLI description\n if (metadata.description) {\n msg += formatTitle(\"Description\") + ln(1);\n msg += indent(2) + c.description(metadata.description) + ln(2);\n }\n\n let longest = 0;\n\n // Prepare CLI options\n const optionsMetadata = metadata.options;\n\n const longestOptionTitle = optionsMetadata.reduce((acc, metadata) => {\n const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]).join(\", \");\n const optLength = names.length + metadata.placeholder.length;\n return optLength > acc ? optLength : acc;\n }, 0);\n\n if (longestOptionTitle > longest) {\n longest = longestOptionTitle;\n }\n\n // Prepare CLI commands\n const subcommandsMetadata = metadata.subcommands;\n\n const longestSubcommandTitle = subcommandsMetadata.reduce((acc, metadata) => {\n const names = metadata.aliases.concat([metadata.name]).join(\", \");\n const placeholder = subcommandPlaceholder(metadata);\n const optLength = names.length + placeholder.length;\n return optLength > acc ? optLength : acc;\n }, 0);\n\n if (longestSubcommandTitle > longest) {\n longest = longestSubcommandTitle;\n }\n\n // Prepare CLI arguments\n const argsMetadata = metadata.arguments;\n const longestArgTitle = argsMetadata.reduce((acc, arg) => (arg.name.length > acc ? arg.name.length : acc), 0);\n if (longestArgTitle > longest) {\n longest = longestArgTitle;\n }\n\n // CLI options\n msg += formatHelpMsgOptions(optionsMetadata, c, longest);\n\n // CLI commands\n msg += formatHelpMsgCommands(subcommandsMetadata, c, longest);\n\n // CLI arguments\n msg += formatHelpMsgArguments(argsMetadata, c, longest);\n\n // CLI example\n if (metadata.example) {\n msg += formatTitle(\"Example\");\n msg += ln(1);\n const normalizeExample = metadata.example.replace(/\\n+/g, \"\\n\" + indent(3));\n msg += concat(indent(2), c.example(normalizeExample), ln(2));\n }\n\n return msg;\n}\n\nexport function formatSubcommandHelpMsg(subcommand: Subcommand, printStyle?: Partial<HelpMsgStyle>, cliName = \"\") {\n const c = helpMsgStyles.default;\n if (printStyle) Object.assign(c, printStyle);\n\n const usage =\n subcommand.usage ||\n concat(\n c.punctuation(\"$\"),\n cliName,\n c.command(subcommand.name),\n subcommand.options?.length ? c.option(\"[options]\") : \"\",\n subcommand.arguments?.length || subcommand.allowPositional ? c.argument(\"<arguments>\") : \"\",\n );\n\n const asCli: Cli = { cliName, usage, ...subcommand };\n\n return formatCliHelpMsg([asCli], c);\n}\n\nexport function printCliHelp(params: readonly [Cli, ...Subcommand[]], style?: Partial<HelpMsgStyle>) {\n console.log(formatCliHelpMsg(params, style));\n}\n\nexport function printSubcommandHelp(subcommand: Subcommand, style?: Partial<HelpMsgStyle>, cliName = \"\") {\n console.log(formatSubcommandHelpMsg(subcommand, style, cliName));\n}\n"],"mappings":"AAAA,OAASA,cAAc,KAAQ,iCAAiC,CAChE,OAASC,MAAM,CAAEC,MAAM,CAAEC,EAAE,CAAEC,qBAAqB,KAAQ,aAAa,CACvE,OAASC,sBAAsB,KAAQ,uBAAuB,CAC9D,OAASC,oBAAoB,KAAQ,qBAAqB,CAC1D,OAASC,qBAAqB,KAAQ,yBAAyB,CAC/D,OAASC,aAAa,KAAQ,aAAa,CAI3C,MAAO,SAAS,CAAAC,gBAAgBA,CAACC,MAAuC,CAAEC,KAA6B,CAAU,CAC/G,KAAM,CAAAC,CAAC,CAAGJ,aAAa,CAACK,OAAO,CAC/B,GAAIF,KAAK,CAAEG,MAAM,CAACC,MAAM,CAACH,CAAC,CAAED,KAAK,CAAC,CAElC,KAAM,CAAAK,QAAQ,CAAGhB,cAAc,CAACU,MAAM,CAAC,CAEvC,KAAM,CAAAO,WAAW,CAAIC,KAAa,EAAKN,CAAC,CAACM,KAAK,CAAC,IAAIA,KAAK,CAACC,WAAW,CAAC,CAAC,EAAE,CAAC,CAEzE,GAAI,CAAAC,GAAG,CAAG,EAAE,CAGZ,KAAM,CAAAC,KAAK,CACTL,QAAQ,CAACK,KAAK,EACdpB,MAAM,CACJW,CAAC,CAACU,WAAW,CAAC,GAAG,CAAC,CAClBV,CAAC,CAACW,WAAW,CAACP,QAAQ,CAACQ,IAAI,CAAC,CAC5BR,QAAQ,CAACS,WAAW,CAAC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,CAAED,OAAO,CAAEnC,KAAK,CAAE,GAAGiC,UAAW,CAAC,CAEpD,MAAO,CAAA7C,gBAAgB,CAAC,CAACgD,KAAK,CAAC,CAAE7C,CAAC,CAAC,CACrC,CAEA,MAAO,SAAS,CAAA8C,YAAYA,CAAChD,MAAuC,CAAEC,KAA6B,CAAE,CACnGgD,OAAO,CAACC,GAAG,CAACnD,gBAAgB,CAACC,MAAM,CAAEC,KAAK,CAAC,CAAC,CAC9C,CAEA,MAAO,SAAS,CAAAkD,mBAAmBA,CAACP,UAAsB,CAAE3C,KAA6B,CAAE6C,OAAO,CAAG,EAAE,CAAE,CACvGG,OAAO,CAACC,GAAG,CAACP,uBAAuB,CAACC,UAAU,CAAE3C,KAAK,CAAE6C,OAAO,CAAC,CAAC,CAClE","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{concat,indent,insertAtEndOfFirstLine,ln}from"../utils.js";export function formatHelpMsgOptions(optionsMetadata,c,longest){if(!optionsMetadata.length)return"";let msg=c.title(" OPTIONS")+ln(1);for(const metadata of optionsMetadata){const names=metadata.aliasesAsArgs.concat([metadata.nameAsArg]);const normalizeDesc=metadata.description.replace(/\n
|
|
1
|
+
import{concat,indent,insertAtEndOfFirstLine,ln}from"../utils.js";export function formatHelpMsgOptions(optionsMetadata,c,longest){if(!optionsMetadata.length)return"";let msg=c.title(" OPTIONS")+ln(1);for(const metadata of optionsMetadata){const names=metadata.aliasesAsArgs.concat([metadata.nameAsArg]);const normalizeDesc=metadata.description.replace(/\n+/g,"\n"+indent(longest+6)+c.punctuation("└"));const defaultStr=typeof metadata.defaultValue!=="undefined"?`(default: ${metadata.defaultValueAsString})`:"";const optLength=names.join(", ").length+metadata.placeholder.length;const spacing=longest+1-optLength;const coloredNames=names.map(name=>c.option(name)).join(c.punctuation(", "));const defaultOrOptional=defaultStr?c.default(defaultStr):metadata.optional?c.optional("(optional)"):"";msg+=concat(indent(2)+coloredNames,c.placeholder(metadata.placeholder),indent(spacing),insertAtEndOfFirstLine(c.description(normalizeDesc),defaultOrOptional),ln(1));if(metadata.example){const normalizeExample=metadata.example.replace(/\n+/g,"\n"+indent(longest+16));msg+=concat(indent(longest+6)+c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample)+ln(1));}}msg+=ln(1);return msg;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["concat","indent","insertAtEndOfFirstLine","ln","formatHelpMsgOptions","optionsMetadata","c","longest","length","msg","title","metadata","names","aliasesAsArgs","nameAsArg","normalizeDesc","description","replace","punctuation","defaultStr","defaultValue","defaultValueAsString","optLength","join","placeholder","spacing","coloredNames","map","name","option","defaultOrOptional","default","optional","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-options.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { OptionMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgOptions(optionsMetadata: OptionMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!optionsMetadata.length) return \"\";\n\n let msg = c.title(\" OPTIONS\") + ln(1);\n\n for (const metadata of optionsMetadata) {\n const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]);\n const normalizeDesc = metadata.description.replace(/\\n
|
|
1
|
+
{"version":3,"names":["concat","indent","insertAtEndOfFirstLine","ln","formatHelpMsgOptions","optionsMetadata","c","longest","length","msg","title","metadata","names","aliasesAsArgs","nameAsArg","normalizeDesc","description","replace","punctuation","defaultStr","defaultValue","defaultValueAsString","optLength","join","placeholder","spacing","coloredNames","map","name","option","defaultOrOptional","default","optional","example","normalizeExample","exampleTitle"],"sourceRoot":"../../../src/help-message","sources":["format-options.ts"],"sourcesContent":["import { concat, indent, insertAtEndOfFirstLine, ln } from \"../utils.js\";\n\nimport type { OptionMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgOptions(optionsMetadata: OptionMetadata[], c: HelpMsgStyle, longest: number): string {\n if (!optionsMetadata.length) return \"\";\n\n let msg = c.title(\" OPTIONS\") + ln(1);\n\n for (const metadata of optionsMetadata) {\n const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]);\n const normalizeDesc = metadata.description.replace(/\\n+/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n const defaultStr =\n typeof metadata.defaultValue !== \"undefined\" ? `(default: ${metadata.defaultValueAsString})` : \"\";\n\n const optLength = names.join(\", \").length + metadata.placeholder.length;\n const spacing = longest + 1 - optLength;\n\n const coloredNames = names.map(name => c.option(name)).join(c.punctuation(\", \"));\n\n const defaultOrOptional = defaultStr ? c.default(defaultStr) : metadata.optional ? c.optional(\"(optional)\") : \"\";\n\n msg += concat(\n indent(2) + coloredNames,\n c.placeholder(metadata.placeholder),\n indent(spacing),\n insertAtEndOfFirstLine(c.description(normalizeDesc), defaultOrOptional),\n ln(1),\n );\n\n if (metadata.example) {\n const normalizeExample = metadata.example.replace(/\\n+/g, \"\\n\" + indent(longest + 16));\n msg += concat(\n indent(longest + 6) + c.punctuation(\"└\") + c.exampleTitle(\"Example:\"),\n c.example(normalizeExample) + ln(1),\n );\n }\n }\n\n msg += ln(1);\n\n return msg;\n}\n"],"mappings":"AAAA,OAASA,MAAM,CAAEC,MAAM,CAAEC,sBAAsB,CAAEC,EAAE,KAAQ,aAAa,CAKxE,MAAO,SAAS,CAAAC,oBAAoBA,CAACC,eAAiC,CAAEC,CAAe,CAAEC,OAAe,CAAU,CAChH,GAAI,CAACF,eAAe,CAACG,MAAM,CAAE,MAAO,EAAE,CAEtC,GAAI,CAAAC,GAAG,CAAGH,CAAC,CAACI,KAAK,CAAC,UAAU,CAAC,CAAGP,EAAE,CAAC,CAAC,CAAC,CAErC,IAAK,KAAM,CAAAQ,QAAQ,GAAI,CAAAN,eAAe,CAAE,CACtC,KAAM,CAAAO,KAAK,CAAGD,QAAQ,CAACE,aAAa,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pB,KAAM,CAAAC,gBAAgB,CAAGvB,QAAQ,CAACsB,OAAO,CAAChB,OAAO,CAAC,MAAM,CAAE,IAAI,CAAGhB,MAAM,CAACM,OAAO,CAAG,EAAE,CAAC,CAAC,CACtFE,GAAG,EAAIT,MAAM,CACXC,MAAM,CAACM,OAAO,CAAG,CAAC,CAAC,CAAGD,CAAC,CAACY,WAAW,CAAC,GAAG,CAAC,CAAGZ,CAAC,CAAC6B,YAAY,CAAC,UAAU,CAAC,CACrE7B,CAAC,CAAC2B,OAAO,CAACC,gBAAgB,CAAC,CAAG/B,EAAE,CAAC,CAAC,CACpC,CAAC,CACH,CACF,CAEAM,GAAG,EAAIN,EAAE,CAAC,CAAC,CAAC,CAEZ,MAAO,CAAAM,GAAG,CACZ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{concat,indent,ln}from"../utils.js";export function formatHelpMsgCommands(subcommandsMetadata,c,longest){if(!subcommandsMetadata.length)return"";let msg=c.title(" COMMANDS")+ln(1);for(const metadata of subcommandsMetadata){const names=metadata.aliases.concat([metadata.name]);const placeholder=
|
|
1
|
+
import{concat,indent,ln,subcommandPlaceholder}from"../utils.js";export function formatHelpMsgCommands(subcommandsMetadata,c,longest){if(!subcommandsMetadata.length)return"";let msg=c.title(" COMMANDS")+ln(1);for(const metadata of subcommandsMetadata){const names=metadata.aliases.concat([metadata.name]);const placeholder=subcommandPlaceholder(metadata);const normalizeDesc=metadata.description.replace(/\n+/g,"\n"+indent(longest+6)+c.punctuation("└"));const optLength=names.join(", ").length+placeholder.length;const spacing=longest+1-optLength;const coloredNames=names.map(name=>c.command(name)).join(c.punctuation(", "));msg+=concat(indent(2)+coloredNames,c.placeholder(placeholder),indent(spacing),c.description(normalizeDesc)+ln(1));}msg+=ln(1);return msg;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["concat","indent","ln","formatHelpMsgCommands","subcommandsMetadata","c","longest","length","msg","title","metadata","names","aliases","name","placeholder","
|
|
1
|
+
{"version":3,"names":["concat","indent","ln","subcommandPlaceholder","formatHelpMsgCommands","subcommandsMetadata","c","longest","length","msg","title","metadata","names","aliases","name","placeholder","normalizeDesc","description","replace","punctuation","optLength","join","spacing","coloredNames","map","command"],"sourceRoot":"../../../src/help-message","sources":["format-subcommands.ts"],"sourcesContent":["import { concat, indent, ln, subcommandPlaceholder } from \"../utils.js\";\n\nimport type { SubcommandMetadata } from \"../metadata/metadata-types.js\";\nimport type { HelpMsgStyle } from \"../types.js\";\n\nexport function formatHelpMsgCommands(\n subcommandsMetadata: SubcommandMetadata[],\n c: HelpMsgStyle,\n longest: number,\n): string {\n if (!subcommandsMetadata.length) return \"\";\n\n let msg = c.title(\" COMMANDS\") + ln(1);\n\n for (const metadata of subcommandsMetadata) {\n const names = metadata.aliases.concat([metadata.name]);\n const placeholder = subcommandPlaceholder(metadata);\n const normalizeDesc = metadata.description.replace(/\\n+/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n\n const optLength = names.join(\", \").length + placeholder.length;\n const spacing = longest + 1 - optLength;\n\n const coloredNames = names.map(name => c.command(name)).join(c.punctuation(\", \"));\n\n msg += concat(\n indent(2) + coloredNames,\n c.placeholder(placeholder),\n indent(spacing),\n c.description(normalizeDesc) + ln(1),\n );\n }\n\n msg += ln(1);\n\n return msg;\n}\n"],"mappings":"AAAA,OAASA,MAAM,CAAEC,MAAM,CAAEC,EAAE,CAAEC,qBAAqB,KAAQ,aAAa,CAKvE,MAAO,SAAS,CAAAC,qBAAqBA,CACnCC,mBAAyC,CACzCC,CAAe,CACfC,OAAe,CACP,CACR,GAAI,CAACF,mBAAmB,CAACG,MAAM,CAAE,MAAO,EAAE,CAE1C,GAAI,CAAAC,GAAG,CAAGH,CAAC,CAACI,KAAK,CAAC,WAAW,CAAC,CAAGR,EAAE,CAAC,CAAC,CAAC,CAEtC,IAAK,KAAM,CAAAS,QAAQ,GAAI,CAAAN,mBAAmB,CAAE,CAC1C,KAAM,CAAAO,KAAK,CAAGD,QAAQ,CAACE,OAAO,CAACb,MAAM,CAAC,CAACW,QAAQ,CAACG,IAAI,CAAC,CAAC,CACtD,KAAM,CAAAC,WAAW,CAAGZ,qBAAqB,CAACQ,QAAQ,CAAC,CACnD,KAAM,CAAAK,aAAa,CAAGL,QAAQ,CAACM,WAAW,CAACC,OAAO,CAAC,MAAM,CAAE,IAAI,CAAGjB,MAAM,CAACM,OAAO,CAAG,CAAC,CAAC,CAAGD,CAAC,CAACa,WAAW,CAAC,GAAG,CAAC,CAAC,CAE3G,KAAM,CAAAC,SAAS,CAAGR,KAAK,CAACS,IAAI,CAAC,IAAI,CAAC,CAACb,MAAM,CAAGO,WAAW,CAACP,MAAM,CAC9D,KAAM,CAAAc,OAAO,CAAGf,OAAO,CAAG,CAAC,CAAGa,SAAS,CAEvC,KAAM,CAAAG,YAAY,CAAGX,KAAK,CAACY,GAAG,CAACV,IAAI,EAAIR,CAAC,CAACmB,OAAO,CAACX,IAAI,CAAC,CAAC,CAACO,IAAI,CAACf,CAAC,CAACa,WAAW,CAAC,IAAI,CAAC,CAAC,CAEjFV,GAAG,EAAIT,MAAM,CACXC,MAAM,CAAC,CAAC,CAAC,CAAGsB,YAAY,CACxBjB,CAAC,CAACS,WAAW,CAACA,WAAW,CAAC,CAC1Bd,MAAM,CAACqB,OAAO,CAAC,CACfhB,CAAC,CAACW,WAAW,CAACD,aAAa,CAAC,CAAGd,EAAE,CAAC,CAAC,CACrC,CAAC,CACH,CAEAO,GAAG,EAAIP,EAAE,CAAC,CAAC,CAAC,CAEZ,MAAO,CAAAO,GAAG,CACZ","ignoreList":[]}
|
package/lib/module/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function stringToBoolean(str){if(str.toLowerCase()==="true"){return true;}if(str.toLowerCase()==="false"){return false;}return str;}export function generateOrdinalSuffix(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}export function ln(count){return"\n".repeat(count);}export function indent(count){return" ".repeat(count);}export function concat(...messages){return messages.join(" ");}export function stringifyValue(value){if(value instanceof Set){return"new Set(["+Array.from(value).map(stringifyValue).join(", ")+"])";}return JSON.stringify(value);}export function insertAtEndOfFirstLine(str,insert){const lines=str.split("\n");lines[0]+=" "+insert;return lines.join("\n");}
|
|
1
|
+
export function stringToBoolean(str){if(str.toLowerCase()==="true"){return true;}if(str.toLowerCase()==="false"){return false;}return str;}export function generateOrdinalSuffix(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}export function ln(count){return"\n".repeat(count);}export function indent(count){if(count<=0)return"";return" ".repeat(count);}export function concat(...messages){return messages.join(" ");}export function stringifyValue(value){if(value instanceof Set){return"new Set(["+Array.from(value).map(stringifyValue).join(", ")+"])";}return JSON.stringify(value);}export function insertAtEndOfFirstLine(str,insert){const lines=str.split("\n");lines[0]+=" "+insert;return lines.join("\n");}export function subcommandPlaceholder(metadata){let placeholder=metadata.placeholder;if(!placeholder&&metadata.options.length){placeholder="[options]";}if(!placeholder&&metadata.arguments.length){placeholder="<arguments>";}if(metadata.allowPositional){placeholder+=(placeholder?" ":"")+"<positionals>";}if(!placeholder){placeholder=" ";}return placeholder;}
|
package/lib/module/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["stringToBoolean","str","toLowerCase","generateOrdinalSuffix","index","suffixes","lastDigit","lastTwoDigits","suffix","ln","count","repeat","indent","concat","messages","join","stringifyValue","value","Set","Array","from","map","JSON","stringify","insertAtEndOfFirstLine","insert","lines","split"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["/**\n * Converts a string to its corresponding boolean value if the string is \"true\" or \"false\" (case-insensitive).\n *\n * @param str - The input string to convert.\n * @returns `true` if the input is \"true\", `false` if the input is \"false\", or the original string otherwise.\n */\nexport function stringToBoolean(str: string): boolean | string {\n if (str.toLowerCase() === \"true\") {\n return true;\n }\n\n if (str.toLowerCase() === \"false\") {\n return false;\n }\n\n return str;\n}\n\n/**\n * Returns the ordinal representation of a given zero-based index.\n *\n * For example, passing `0` returns `\"1st\"`, `1` returns `\"2nd\"`, and so on.\n *\n * Handles special cases for numbers ending in 11, 12, or 13 (e.g., `10` returns `\"11th\"`).\n *\n * @param index - The zero-based index to convert to an ordinal string.\n * @returns The ordinal string representation (e.g., `\"1st\"`, `\"2nd\"`, `\"3rd\"`, `\"4th\"`, ...).\n */\nexport function generateOrdinalSuffix(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** New line */\nexport function ln(count: number) {\n return \"\\n\".repeat(count);\n}\n\n/** Space */\nexport function indent(count: number) {\n return \" \".repeat(count);\n}\n\n/** Concat strings */\nexport function concat(...messages: string[]) {\n // messages = messages.filter(Boolean);\n return messages.join(\" \");\n}\n\nexport function stringifyValue(value: unknown): string {\n // Set\n if (value instanceof Set) {\n return \"new Set([\" + Array.from(value).map(stringifyValue).join(\", \") + \"])\";\n }\n\n // unknown\n return JSON.stringify(value);\n}\n\n/** Insert text at the end of the first line */\nexport function insertAtEndOfFirstLine(str: string, insert: string) {\n const lines = str.split(\"\\n\");\n lines[0] += \" \" + insert;\n return lines.join(\"\\n\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["stringToBoolean","str","toLowerCase","generateOrdinalSuffix","index","suffixes","lastDigit","lastTwoDigits","suffix","ln","count","repeat","indent","concat","messages","join","stringifyValue","value","Set","Array","from","map","JSON","stringify","insertAtEndOfFirstLine","insert","lines","split","subcommandPlaceholder","metadata","placeholder","options","length","arguments","allowPositional"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import { SubcommandMetadata } from \"./metadata/metadata-types.js\";\n\n/**\n * Converts a string to its corresponding boolean value if the string is \"true\" or \"false\" (case-insensitive).\n *\n * @param str - The input string to convert.\n * @returns `true` if the input is \"true\", `false` if the input is \"false\", or the original string otherwise.\n */\nexport function stringToBoolean(str: string): boolean | string {\n if (str.toLowerCase() === \"true\") {\n return true;\n }\n\n if (str.toLowerCase() === \"false\") {\n return false;\n }\n\n return str;\n}\n\n/**\n * Returns the ordinal representation of a given zero-based index.\n *\n * For example, passing `0` returns `\"1st\"`, `1` returns `\"2nd\"`, and so on.\n *\n * Handles special cases for numbers ending in 11, 12, or 13 (e.g., `10` returns `\"11th\"`).\n *\n * @param index - The zero-based index to convert to an ordinal string.\n * @returns The ordinal string representation (e.g., `\"1st\"`, `\"2nd\"`, `\"3rd\"`, `\"4th\"`, ...).\n */\nexport function generateOrdinalSuffix(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** New line */\nexport function ln(count: number) {\n return \"\\n\".repeat(count);\n}\n\n/** Space */\nexport function indent(count: number) {\n if (count <= 0) return \"\";\n return \" \".repeat(count);\n}\n\n/** Concat strings */\nexport function concat(...messages: string[]) {\n // messages = messages.filter(Boolean);\n return messages.join(\" \");\n}\n\nexport function stringifyValue(value: unknown): string {\n // Set\n if (value instanceof Set) {\n return \"new Set([\" + Array.from(value).map(stringifyValue).join(\", \") + \"])\";\n }\n\n // unknown\n return JSON.stringify(value);\n}\n\n/** Insert text at the end of the first line */\nexport function insertAtEndOfFirstLine(str: string, insert: string) {\n const lines = str.split(\"\\n\");\n lines[0] += \" \" + insert;\n return lines.join(\"\\n\");\n}\n\n/** Get the placeholder for a subcommand */\nexport function subcommandPlaceholder(metadata: SubcommandMetadata): string {\n let placeholder = metadata.placeholder;\n\n if (!placeholder && metadata.options.length) {\n placeholder = \"[options]\";\n }\n\n if (!placeholder && metadata.arguments.length) {\n placeholder = \"<arguments>\";\n }\n\n if (metadata.allowPositional) {\n placeholder += (placeholder ? \" \" : \"\") + \"<positionals>\";\n }\n\n if (!placeholder) {\n placeholder = \" \";\n }\n\n return placeholder;\n}\n"],"mappings":"AAQA,MAAO,SAAS,CAAAA,eAAeA,CAACC,GAAW,CAAoB,CAC7D,GAAIA,GAAG,CAACC,WAAW,CAAC,CAAC,GAAK,MAAM,CAAE,CAChC,MAAO,KAAI,CACb,CAEA,GAAID,GAAG,CAACC,WAAW,CAAC,CAAC,GAAK,OAAO,CAAE,CACjC,MAAO,MAAK,CACd,CAEA,MAAO,CAAAD,GAAG,CACZ,CAYA,MAAO,SAAS,CAAAE,qBAAqBA,CAACC,KAAa,CAAU,CAC3D,GAAIA,KAAK,CAAG,CAAC,CAAE,MAAO,EAAE,CAExB,KAAM,CAAAC,QAAQ,CAAG,CAAC,IAAI,CAAE,IAAI,CAAE,IAAI,CAAE,IAAI,CAAC,CACzC,KAAM,CAAAC,SAAS,CAAGF,KAAK,CAAG,EAAE,CAC5B,KAAM,CAAAG,aAAa,CAAGH,KAAK,CAAG,GAAG,CAEjC,KAAM,CAAAI,MAAM,CACVF,SAAS,GAAK,CAAC,EAAIC,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,IAAI,CAAC,CACzB,CAGA,MAAO,SAAS,CAAAa,qBAAqBA,CAACC,QAA4B,CAAU,CAC1E,GAAI,CAAAC,WAAW,CAAGD,QAAQ,CAACC,WAAW,CAEtC,GAAI,CAACA,WAAW,EAAID,QAAQ,CAACE,OAAO,CAACC,MAAM,CAAE,CAC3CF,WAAW,CAAG,WAAW,CAC3B,CAEA,GAAI,CAACA,WAAW,EAAID,QAAQ,CAACI,SAAS,CAACD,MAAM,CAAE,CAC7CF,WAAW,CAAG,aAAa,CAC7B,CAEA,GAAID,QAAQ,CAACK,eAAe,CAAE,CAC5BJ,WAAW,EAAI,CAACA,WAAW,CAAG,GAAG,CAAG,EAAE,EAAI,eAAe,CAC3D,CAEA,GAAI,CAACA,WAAW,CAAE,CAChBA,WAAW,CAAG,GAAG,CACnB,CAEA,MAAO,CAAAA,WAAW,CACpB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-subcommands.d.ts","sourceRoot":"","sources":["../../../src/help-message/format-subcommands.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,kBAAkB,EAAE,EACzC,CAAC,EAAE,YAAY,EACf,OAAO,EAAE,MAAM,GACd,MAAM,
|
|
1
|
+
{"version":3,"file":"format-subcommands.d.ts","sourceRoot":"","sources":["../../../src/help-message/format-subcommands.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,kBAAkB,EAAE,EACzC,CAAC,EAAE,YAAY,EACf,OAAO,EAAE,MAAM,GACd,MAAM,CA0BR"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SubcommandMetadata } from "./metadata/metadata-types.js";
|
|
1
2
|
/**
|
|
2
3
|
* Converts a string to its corresponding boolean value if the string is "true" or "false" (case-insensitive).
|
|
3
4
|
*
|
|
@@ -25,4 +26,6 @@ export declare function concat(...messages: string[]): string;
|
|
|
25
26
|
export declare function stringifyValue(value: unknown): string;
|
|
26
27
|
/** Insert text at the end of the first line */
|
|
27
28
|
export declare function insertAtEndOfFirstLine(str: string, insert: string): string;
|
|
29
|
+
/** Get the placeholder for a subcommand */
|
|
30
|
+
export declare function subcommandPlaceholder(metadata: SubcommandMetadata): string;
|
|
28
31
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAU7D;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB3D;AAED,eAAe;AACf,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,UAE/B;AAED,YAAY;AACZ,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAU7D;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB3D;AAED,eAAe;AACf,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,UAE/B;AAED,YAAY;AACZ,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,UAGnC;AAED,qBAAqB;AACrB,wBAAgB,MAAM,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,UAG3C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQrD;AAED,+CAA+C;AAC/C,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAIjE;AAED,2CAA2C;AAC3C,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAoB1E"}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ export function formatHelpMsgArguments(argsMetadata: ArgumentMetadata[], c: Help
|
|
|
13
13
|
typeof metadata.defaultValue !== "undefined" ? `(default: ${metadata.defaultValueAsString})` : "";
|
|
14
14
|
|
|
15
15
|
const spacing = longest + 2 - metadata.name.length;
|
|
16
|
-
const normalizeDesc = metadata.description.replace(/\n
|
|
16
|
+
const normalizeDesc = metadata.description.replace(/\n+/g, "\n" + indent(longest + 6) + c.punctuation("└"));
|
|
17
17
|
const defaultOrOptional = defaultStr ? c.default(defaultStr) : metadata.optional ? c.optional("(optional)") : "";
|
|
18
18
|
|
|
19
19
|
msg += concat(
|
|
@@ -24,7 +24,7 @@ export function formatHelpMsgArguments(argsMetadata: ArgumentMetadata[], c: Help
|
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
if (metadata.example) {
|
|
27
|
-
const normalizeExample = metadata.example.replace(/\n
|
|
27
|
+
const normalizeExample = metadata.example.replace(/\n+/g, "\n" + indent(longest + 16));
|
|
28
28
|
msg += concat(
|
|
29
29
|
indent(longest + 5),
|
|
30
30
|
c.punctuation("└") + c.exampleTitle("Example:"),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCliMetadata } from "../metadata/get-cli-metadata.js";
|
|
2
|
-
import { concat, indent, ln } from "../utils.js";
|
|
2
|
+
import { concat, indent, ln, subcommandPlaceholder } from "../utils.js";
|
|
3
3
|
import { formatHelpMsgArguments } from "./format-arguments.js";
|
|
4
4
|
import { formatHelpMsgOptions } from "./format-options.js";
|
|
5
5
|
import { formatHelpMsgCommands } from "./format-subcommands.js";
|
|
@@ -25,7 +25,8 @@ export function formatCliHelpMsg(params: readonly [Cli, ...Subcommand[]], style?
|
|
|
25
25
|
c.description(metadata.name),
|
|
26
26
|
metadata.subcommands.length ? c.command("[command]") : "",
|
|
27
27
|
metadata.options.length ? c.option("[options]") : "",
|
|
28
|
-
metadata.arguments.length
|
|
28
|
+
metadata.arguments.length ? c.argument("<arguments>") : "",
|
|
29
|
+
metadata.allowPositional ? c.argument("<positionals>") : "",
|
|
29
30
|
);
|
|
30
31
|
msg += formatTitle("Usage") + ln(1);
|
|
31
32
|
msg += indent(2) + usage + ln(2);
|
|
@@ -56,8 +57,7 @@ export function formatCliHelpMsg(params: readonly [Cli, ...Subcommand[]], style?
|
|
|
56
57
|
|
|
57
58
|
const longestSubcommandTitle = subcommandsMetadata.reduce((acc, metadata) => {
|
|
58
59
|
const names = metadata.aliases.concat([metadata.name]).join(", ");
|
|
59
|
-
const placeholder =
|
|
60
|
-
metadata.placeholder || (metadata.options.length ? "[options]" : metadata.allowPositional ? "<args>" : " ");
|
|
60
|
+
const placeholder = subcommandPlaceholder(metadata);
|
|
61
61
|
const optLength = names.length + placeholder.length;
|
|
62
62
|
return optLength > acc ? optLength : acc;
|
|
63
63
|
}, 0);
|
|
@@ -86,7 +86,7 @@ export function formatCliHelpMsg(params: readonly [Cli, ...Subcommand[]], style?
|
|
|
86
86
|
if (metadata.example) {
|
|
87
87
|
msg += formatTitle("Example");
|
|
88
88
|
msg += ln(1);
|
|
89
|
-
const normalizeExample = metadata.example.replace(/\n
|
|
89
|
+
const normalizeExample = metadata.example.replace(/\n+/g, "\n" + indent(3));
|
|
90
90
|
msg += concat(indent(2), c.example(normalizeExample), ln(2));
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -10,7 +10,7 @@ export function formatHelpMsgOptions(optionsMetadata: OptionMetadata[], c: HelpM
|
|
|
10
10
|
|
|
11
11
|
for (const metadata of optionsMetadata) {
|
|
12
12
|
const names = metadata.aliasesAsArgs.concat([metadata.nameAsArg]);
|
|
13
|
-
const normalizeDesc = metadata.description.replace(/\n
|
|
13
|
+
const normalizeDesc = metadata.description.replace(/\n+/g, "\n" + indent(longest + 6) + c.punctuation("└"));
|
|
14
14
|
const defaultStr =
|
|
15
15
|
typeof metadata.defaultValue !== "undefined" ? `(default: ${metadata.defaultValueAsString})` : "";
|
|
16
16
|
|
|
@@ -30,7 +30,7 @@ export function formatHelpMsgOptions(optionsMetadata: OptionMetadata[], c: HelpM
|
|
|
30
30
|
);
|
|
31
31
|
|
|
32
32
|
if (metadata.example) {
|
|
33
|
-
const normalizeExample = metadata.example.replace(/\n
|
|
33
|
+
const normalizeExample = metadata.example.replace(/\n+/g, "\n" + indent(longest + 16));
|
|
34
34
|
msg += concat(
|
|
35
35
|
indent(longest + 6) + c.punctuation("└") + c.exampleTitle("Example:"),
|
|
36
36
|
c.example(normalizeExample) + ln(1),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { concat, indent, ln } from "../utils.js";
|
|
1
|
+
import { concat, indent, ln, subcommandPlaceholder } from "../utils.js";
|
|
2
2
|
|
|
3
3
|
import type { SubcommandMetadata } from "../metadata/metadata-types.js";
|
|
4
4
|
import type { HelpMsgStyle } from "../types.js";
|
|
@@ -14,9 +14,8 @@ export function formatHelpMsgCommands(
|
|
|
14
14
|
|
|
15
15
|
for (const metadata of subcommandsMetadata) {
|
|
16
16
|
const names = metadata.aliases.concat([metadata.name]);
|
|
17
|
-
const placeholder =
|
|
18
|
-
|
|
19
|
-
const normalizeDesc = metadata.description.replace(/\n/g, "\n" + indent(longest + 7) + c.punctuation("└"));
|
|
17
|
+
const placeholder = subcommandPlaceholder(metadata);
|
|
18
|
+
const normalizeDesc = metadata.description.replace(/\n+/g, "\n" + indent(longest + 6) + c.punctuation("└"));
|
|
20
19
|
|
|
21
20
|
const optLength = names.join(", ").length + placeholder.length;
|
|
22
21
|
const spacing = longest + 1 - optLength;
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SubcommandMetadata } from "./metadata/metadata-types.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Converts a string to its corresponding boolean value if the string is "true" or "false" (case-insensitive).
|
|
3
5
|
*
|
|
@@ -52,6 +54,7 @@ export function ln(count: number) {
|
|
|
52
54
|
|
|
53
55
|
/** Space */
|
|
54
56
|
export function indent(count: number) {
|
|
57
|
+
if (count <= 0) return "";
|
|
55
58
|
return " ".repeat(count);
|
|
56
59
|
}
|
|
57
60
|
|
|
@@ -77,3 +80,26 @@ export function insertAtEndOfFirstLine(str: string, insert: string) {
|
|
|
77
80
|
lines[0] += " " + insert;
|
|
78
81
|
return lines.join("\n");
|
|
79
82
|
}
|
|
83
|
+
|
|
84
|
+
/** Get the placeholder for a subcommand */
|
|
85
|
+
export function subcommandPlaceholder(metadata: SubcommandMetadata): string {
|
|
86
|
+
let placeholder = metadata.placeholder;
|
|
87
|
+
|
|
88
|
+
if (!placeholder && metadata.options.length) {
|
|
89
|
+
placeholder = "[options]";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!placeholder && metadata.arguments.length) {
|
|
93
|
+
placeholder = "<arguments>";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (metadata.allowPositional) {
|
|
97
|
+
placeholder += (placeholder ? " " : "") + "<positionals>";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!placeholder) {
|
|
101
|
+
placeholder = " ";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return placeholder;
|
|
105
|
+
}
|