mirror of
https://github.com/chenasraf/massarg.git
synced 2026-05-18 01:39:05 +00:00
fix: split negation labels to 2 lines
This commit is contained in:
@@ -35,19 +35,7 @@ const config: Config = {
|
|||||||
|
|
||||||
// Plugin / TypeDoc options
|
// Plugin / TypeDoc options
|
||||||
{
|
{
|
||||||
entryPoints: [
|
entryPoints: ['../src/index.ts'],
|
||||||
'../src/*.ts',
|
|
||||||
// '../src/index.ts',
|
|
||||||
// '../src/command.ts',
|
|
||||||
// '../src/error.ts',
|
|
||||||
// '../src/example.ts',
|
|
||||||
// '../src/help.ts',
|
|
||||||
// '../src/massarg.ts',
|
|
||||||
// '../src/option.ts',
|
|
||||||
// '../src/sample.ts',
|
|
||||||
// '../src/style.ts',
|
|
||||||
// '../src/utils.ts',
|
|
||||||
],
|
|
||||||
tsconfig: '../tsconfig.json',
|
tsconfig: '../tsconfig.json',
|
||||||
|
|
||||||
// typedoc options
|
// typedoc options
|
||||||
@@ -105,10 +93,11 @@ const config: Config = {
|
|||||||
},
|
},
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'docSidebar',
|
|
||||||
sidebarId: 'tutorialSidebar',
|
|
||||||
position: 'left',
|
position: 'left',
|
||||||
label: 'Docs',
|
type: 'docSidebar',
|
||||||
|
sidebarId: 'api',
|
||||||
|
label: 'API',
|
||||||
|
to: 'docs/api',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: 'https://npmjs.com/package/massarg',
|
href: 'https://npmjs.com/package/massarg',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs';
|
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creating a sidebar enables you to:
|
* Creating a sidebar enables you to:
|
||||||
@@ -12,7 +12,7 @@ import type {SidebarsConfig} from '@docusaurus/plugin-content-docs';
|
|||||||
*/
|
*/
|
||||||
const sidebars: SidebarsConfig = {
|
const sidebars: SidebarsConfig = {
|
||||||
// By default, Docusaurus generates a sidebar from the docs folder structure
|
// By default, Docusaurus generates a sidebar from the docs folder structure
|
||||||
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
|
api: [{ type: 'autogenerated', dirName: '.' }],
|
||||||
|
|
||||||
// But you can create a sidebar manually
|
// But you can create a sidebar manually
|
||||||
/*
|
/*
|
||||||
@@ -26,6 +26,6 @@ const sidebars: SidebarsConfig = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
*/
|
*/
|
||||||
};
|
}
|
||||||
|
|
||||||
export default sidebars;
|
export default sidebars
|
||||||
|
|||||||
42
src/help.ts
42
src/help.ts
@@ -325,7 +325,7 @@ export class HelpGenerator {
|
|||||||
indent(options),
|
indent(options),
|
||||||
]),
|
]),
|
||||||
examples.length &&
|
examples.length &&
|
||||||
indent(['', format('Examples:', this.config.subtitleStyle), '', indent(examples)]),
|
indent(['', format('Examples:', this.config.subtitleStyle), '', indent(examples)]),
|
||||||
footerText.length && ['', format(footerText, this.config.descriptionStyle)],
|
footerText.length && ['', format(footerText, this.config.descriptionStyle)],
|
||||||
) + '\n'
|
) + '\n'
|
||||||
)
|
)
|
||||||
@@ -367,7 +367,7 @@ type ParsedHelpItem = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getMaxNameLength = (items: ParsedHelpItem[]): number =>
|
const getMaxNameLength = (items: ParsedHelpItem[]): number =>
|
||||||
Math.max(...items.map((o) => o.name.length))
|
Math.max(...items.map((o) => Math.max(...o.name.split('\n').map((c) => c.length))))
|
||||||
|
|
||||||
function getItemDetails(
|
function getItemDetails(
|
||||||
o: HelpItem,
|
o: HelpItem,
|
||||||
@@ -384,18 +384,15 @@ function getItemDetails(
|
|||||||
|
|
||||||
const cmdNames = {
|
const cmdNames = {
|
||||||
full: `${namePrefix}${o.name}`,
|
full: `${namePrefix}${o.name}`,
|
||||||
fullNegated: `${namePrefix}no-${o.name}`,
|
fullNegated: `${namePrefix}${o.negationName}`,
|
||||||
aliases: o.aliases.map((a) => `${aliasPrefix}${a}`).join(' | '),
|
aliases: o.aliases.map((a) => `${aliasPrefix}${a}`).join(' | '),
|
||||||
aliasesNegated: o.aliases.map((a) => `${aliasPrefix}${a}`).join(' | '),
|
aliasesNegated: (o.negationAliases ?? []).map((a) => `${aliasPrefix}${a}`).join(' | '),
|
||||||
}
|
}
|
||||||
const name = [
|
const normal = [cmdNames.full, cmdNames.aliases].filter(Boolean).join(' | ')
|
||||||
cmdNames.full,
|
const negations = [negatable && cmdNames.fullNegated, negatable && cmdNames.aliasesNegated]
|
||||||
cmdNames.aliases,
|
|
||||||
negatable && cmdNames.fullNegated,
|
|
||||||
negatable && cmdNames.aliasesNegated,
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' | ')
|
.join(' | ')
|
||||||
|
const name = [normal, negations].filter(Boolean).join('\n')
|
||||||
return { name, description, hidden, negatable, displayNegations, defaultValue }
|
return { name, description, hidden, negatable, displayNegations, defaultValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,14 +423,19 @@ function generateHelpTable<T extends GenerateTableCommandConfig | GenerateTableO
|
|||||||
const nameStyle = (name: string) => format(name, config.nameStyle)
|
const nameStyle = (name: string) => format(name, config.nameStyle)
|
||||||
const descStyle = (desc: string) => format(desc, config.descriptionStyle)
|
const descStyle = (desc: string) => format(desc, config.descriptionStyle)
|
||||||
const table = rows.map((row) => {
|
const table = rows.map((row) => {
|
||||||
const name = nameStyle(row.name.padEnd(maxNameLength! + 2))
|
const nameLines = row.name.split('\n').map((l) => nameStyle(l).padEnd(maxNameLength! + 2))
|
||||||
let description = descStyle(row.description)
|
let description = descStyle(row.description)
|
||||||
if (displayDefaultValue && row.defaultValue != null) {
|
if (displayDefaultValue && row.defaultValue != null) {
|
||||||
description += ` ${format(`(default: ${row.defaultValue})`, config.defaultValueStyle)}`
|
description += ` ${format(`(default: ${row.defaultValue})`, config.defaultValueStyle)}`
|
||||||
}
|
}
|
||||||
const length = stripStyle(name).length + stripStyle(description).length
|
const firstNameLine = nameStyle(stripStyle(nameLines[0]).padEnd(maxNameLength! + 2))
|
||||||
|
const length =
|
||||||
|
stripStyle(firstNameLine).padEnd(maxNameLength! + 2).length + stripStyle(description).length
|
||||||
if (length <= lineLength) {
|
if (length <= lineLength) {
|
||||||
const line = `${name}${description}`
|
let line = `${firstNameLine}${description}`
|
||||||
|
if (nameLines.length > 1) {
|
||||||
|
line += `\n${nameLines.slice(1).join('\n')}`
|
||||||
|
}
|
||||||
if (!compact) {
|
if (!compact) {
|
||||||
return `${line}\n`
|
return `${line}\n`
|
||||||
}
|
}
|
||||||
@@ -441,15 +443,25 @@ function generateHelpTable<T extends GenerateTableCommandConfig | GenerateTableO
|
|||||||
}
|
}
|
||||||
const subRows: string[] = []
|
const subRows: string[] = []
|
||||||
const words = description.split(' ')
|
const words = description.split(' ')
|
||||||
let currentRow = name
|
let currentRow = firstNameLine
|
||||||
|
let rowCount = 0
|
||||||
|
|
||||||
for (const word of words) {
|
for (const word of words) {
|
||||||
if (stripStyle(currentRow).length + stripStyle(word).length + 1 > lineLength) {
|
if (stripStyle(currentRow).length + stripStyle(word).length + 1 > lineLength) {
|
||||||
subRows.push(currentRow)
|
subRows.push(currentRow)
|
||||||
currentRow = ' '.repeat(maxNameLength! + 2)
|
rowCount++
|
||||||
|
if (rowCount > 0 && rowCount < nameLines.length) {
|
||||||
|
currentRow = nameStyle(stripStyle(nameLines[rowCount]).padEnd(maxNameLength! + 2))
|
||||||
|
currentRow += format('', { ...config.descriptionStyle, reset: false })
|
||||||
|
} else {
|
||||||
|
currentRow = ' '.repeat(maxNameLength! + 2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
currentRow += `${word} `
|
currentRow += `${word} `
|
||||||
}
|
}
|
||||||
|
if (rowCount > 0 && rowCount < nameLines.length) {
|
||||||
|
currentRow += ` ${nameLines[rowCount].padEnd(maxNameLength! + 2)}`
|
||||||
|
}
|
||||||
subRows.push(currentRow)
|
subRows.push(currentRow)
|
||||||
|
|
||||||
if (!compact) {
|
if (!compact) {
|
||||||
|
|||||||
@@ -106,6 +106,14 @@ const main = massarg<A>({
|
|||||||
negatable: true,
|
negatable: true,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
})
|
})
|
||||||
|
.flag({
|
||||||
|
name: 'bool2',
|
||||||
|
description:
|
||||||
|
'Ad consequat eiusmod officia aliqua. Eiusmod officia aliqua amet et laboris. Aliqua amet et laboris officia proident. Et, laboris officia proident minim duis officia. Proident minim, duis officia.',
|
||||||
|
aliases: ['e'],
|
||||||
|
negatable: true,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
.option({
|
.option({
|
||||||
name: 'string',
|
name: 'string',
|
||||||
description:
|
description:
|
||||||
|
|||||||
Reference in New Issue
Block a user