mirror of
https://github.com/chenasraf/massarg.git
synced 2026-05-18 01:39:05 +00:00
fix: help output formatting/text
This commit is contained in:
73
src/help.ts
73
src/help.ts
@@ -57,9 +57,9 @@ export const HelpConfig = z.object({
|
|||||||
inputStyle: StringStyle.optional(),
|
inputStyle: StringStyle.optional(),
|
||||||
/** Style of the example output */
|
/** Style of the example output */
|
||||||
outputStyle: StringStyle.optional(),
|
outputStyle: StringStyle.optional(),
|
||||||
/** Prefix for the example input */
|
/** Prefix for the example input (default: `$`) */
|
||||||
inputPrefix: z.string().default('$').optional(),
|
inputPrefix: z.string().default('$').optional(),
|
||||||
/** Prefix for the example output */
|
/** Prefix for the example output (default: `>`) */
|
||||||
outputPrefix: z.string().default('>').optional(),
|
outputPrefix: z.string().default('>').optional(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
@@ -176,24 +176,24 @@ export class HelpGenerator {
|
|||||||
return strConcat(
|
return strConcat(
|
||||||
description && [
|
description && [
|
||||||
_wrap(format(description, this.config.exampleOptions.descriptionStyle), 4),
|
_wrap(format(description, this.config.exampleOptions.descriptionStyle), 4),
|
||||||
'',
|
|
||||||
],
|
],
|
||||||
input &&
|
input &&
|
||||||
_wrap(
|
_wrap(
|
||||||
format(
|
format(
|
||||||
[this.config.exampleOptions.inputPrefix, input].filter(Boolean).join(' '),
|
[this.config.exampleOptions.inputPrefix, input].filter(Boolean).join(' '),
|
||||||
this.config.exampleOptions.inputStyle,
|
this.config.exampleOptions.inputStyle,
|
||||||
),
|
|
||||||
4,
|
|
||||||
),
|
),
|
||||||
|
4,
|
||||||
|
),
|
||||||
output &&
|
output &&
|
||||||
_wrap(
|
_wrap(
|
||||||
format(
|
format(
|
||||||
[this.config.exampleOptions.outputPrefix, output].filter(Boolean).join(' '),
|
[this.config.exampleOptions.outputPrefix, output].filter(Boolean).join(' '),
|
||||||
this.config.exampleOptions.outputStyle,
|
this.config.exampleOptions.outputStyle,
|
||||||
),
|
|
||||||
4,
|
|
||||||
),
|
),
|
||||||
|
4,
|
||||||
|
),
|
||||||
|
'',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.join('\n')
|
.join('\n')
|
||||||
@@ -204,9 +204,9 @@ export class HelpGenerator {
|
|||||||
_wrap(
|
_wrap(
|
||||||
format(
|
format(
|
||||||
usageText ||
|
usageText ||
|
||||||
[`Usage:`, entry.name, commands.length && '[command]', options.length && '[options]']
|
[`Usage:`, entry.name, commands.length && '[command]', options.length && '[options]']
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' '),
|
.join(' '),
|
||||||
this.config.usageStyle,
|
this.config.usageStyle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -216,21 +216,27 @@ export class HelpGenerator {
|
|||||||
_wrap(format(entry.description, this.config.descriptionStyle)),
|
_wrap(format(entry.description, this.config.descriptionStyle)),
|
||||||
],
|
],
|
||||||
commands.length &&
|
commands.length &&
|
||||||
indent([
|
indent([
|
||||||
'',
|
'',
|
||||||
format(`Commands for ${entry.name}:`, this.config.subtitleStyle),
|
format(
|
||||||
'',
|
entry.parent ? `Commands for ${entry.name}:` : 'Commands:',
|
||||||
indent(commands),
|
this.config.subtitleStyle,
|
||||||
]),
|
),
|
||||||
|
'',
|
||||||
|
indent(commands),
|
||||||
|
]),
|
||||||
options.length &&
|
options.length &&
|
||||||
indent([
|
indent([
|
||||||
'',
|
'',
|
||||||
format(`Options for ${entry.name}:`, this.config.subtitleStyle),
|
format(
|
||||||
'',
|
entry.parent ? `Options for ${entry.name}:` : 'Options:',
|
||||||
indent(options),
|
this.config.subtitleStyle,
|
||||||
]),
|
),
|
||||||
|
'',
|
||||||
|
indent(options),
|
||||||
|
]),
|
||||||
examples.length &&
|
examples.length &&
|
||||||
indent(['', format('Examples:', this.config.subtitleStyle), '', indent(examples)]),
|
indent(['', format('Examples:', this.config.subtitleStyle), '', indent(examples)]),
|
||||||
footerText.length && ['', _wrap(format(footerText, this.config.descriptionStyle))],
|
footerText.length && ['', _wrap(format(footerText, this.config.descriptionStyle))],
|
||||||
) + '\n'
|
) + '\n'
|
||||||
)
|
)
|
||||||
@@ -274,9 +280,8 @@ function generateHelpTable<T extends Partial<GenerateTableCommandConfig>>(
|
|||||||
): string {
|
): string {
|
||||||
const rows = items
|
const rows = items
|
||||||
.map((o) => {
|
.map((o) => {
|
||||||
const name = `${namePrefix}${o.name}${
|
const name = `${namePrefix}${o.name}${o.aliases.length ? ` | ${aliasPrefix}${o.aliases.join(`|${aliasPrefix}`)}` : ''
|
||||||
o.aliases.length ? ` | ${aliasPrefix}${o.aliases.join(`|${aliasPrefix}`)}` : ''
|
}`
|
||||||
}`
|
|
||||||
const description = o.description
|
const description = o.description
|
||||||
const hidden = o.hidden || false
|
const hidden = o.hidden || false
|
||||||
return { name, description, hidden }
|
return { name, description, hidden }
|
||||||
|
|||||||
Reference in New Issue
Block a user