mirror of
https://github.com/chenasraf/massarg.git
synced 2026-05-17 17:38:09 +00:00
fix: add spacing between args, update sample
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright © [year] [fullname]
|
||||
Copyright © 2024 Chen Asraf
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -78,18 +78,20 @@ const parser = massarg({
|
||||
// A subcommand example
|
||||
.command({
|
||||
name: 'foo',
|
||||
description: 'a sub command',
|
||||
description: 'a foo command',
|
||||
aliases: ['f'],
|
||||
// default prefixes:
|
||||
optionPrefix: '--',
|
||||
aliasPrefix: '-',
|
||||
run: (options) => console.log('foo command'), // The function to run
|
||||
// The function to run for this command
|
||||
run: (options) => console.log('foo command', options),
|
||||
})
|
||||
// A subcommand example, which contains its own set of options or sub commands. This is infinitely
|
||||
// nestible.
|
||||
.command(
|
||||
massarg({
|
||||
name: 'bar',
|
||||
description: 'another sub command',
|
||||
description: 'a bar command',
|
||||
aliases: ['s'],
|
||||
run: (options) => console.log('bar command', options),
|
||||
}).option({
|
||||
|
||||
16
src/help.ts
16
src/help.ts
@@ -423,7 +423,9 @@ function generateHelpTable<T extends GenerateTableCommandConfig | GenerateTableO
|
||||
const nameStyle = (name: string) => format(name, config.nameStyle)
|
||||
const descStyle = (desc: string) => format(desc, config.descriptionStyle)
|
||||
const table = rows.map((row) => {
|
||||
const nameLines = row.name.split('\n').map((l) => nameStyle(l.padEnd(maxNameLength! + 2)))
|
||||
const padAmount = 4
|
||||
const pad = (s: string) => s.padEnd(maxNameLength! + padAmount)
|
||||
const nameLines = row.name.split('\n').map((l) => nameStyle(pad(l)))
|
||||
const descLines = wrap(row.description, lineLength - maxNameLength!)
|
||||
.split('\n')
|
||||
.map(descStyle)
|
||||
@@ -431,21 +433,17 @@ function generateHelpTable<T extends GenerateTableCommandConfig | GenerateTableO
|
||||
const subRows: string[] = []
|
||||
|
||||
for (let i = 0; i < max - 1; i++) {
|
||||
subRows.push(`${(nameLines[i] ?? ' ').padEnd(maxNameLength! + 2)}${descLines[i] ?? ''}`)
|
||||
subRows.push(`${pad(nameLines[i] ?? ' ')}${descLines[i] ?? ''}`)
|
||||
}
|
||||
const defaultText =
|
||||
displayDefaultValue && row.defaultValue != null
|
||||
? format(`(default: ${row.defaultValue})`, config.defaultValueStyle)
|
||||
: ''
|
||||
if (subRows.length + 1 + stripStyle(defaultText).length <= lineLength) {
|
||||
subRows.push(
|
||||
`${(nameLines[max - 1] ?? ' ').padEnd(maxNameLength! + 2)}${descLines[max - 1] ?? ''}${defaultText}`,
|
||||
)
|
||||
subRows.push(`${pad(nameLines[max - 1] ?? ' ')}${descLines[max - 1] ?? ''}${defaultText}`)
|
||||
} else {
|
||||
subRows.push(
|
||||
`${(nameLines[max - 1] ?? ' ').padEnd(maxNameLength! + 2)}${descLines[max - 1] ?? ''}`,
|
||||
)
|
||||
subRows.push(defaultText.padStart(maxNameLength! + 2))
|
||||
subRows.push(`${pad(nameLines[max - 1] ?? ' ')}${descLines[max - 1] ?? ''}`)
|
||||
subRows.push(defaultText.padStart(maxNameLength! + padAmount))
|
||||
}
|
||||
|
||||
if (!compact) {
|
||||
|
||||
@@ -83,8 +83,8 @@ const main = massarg<A>({
|
||||
.help({
|
||||
bindOption: true,
|
||||
bindCommand: true,
|
||||
headerText: 'This is a header',
|
||||
footerText: 'This is a footer',
|
||||
headerText: 'This is the header',
|
||||
footerText: 'This is the footer',
|
||||
optionOptions: {
|
||||
displayNegations: true,
|
||||
},
|
||||
@@ -106,25 +106,9 @@ const main = massarg<A>({
|
||||
negatable: true,
|
||||
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. Non commodo ...',
|
||||
aliases: ['e'],
|
||||
negatable: true,
|
||||
defaultValue: false,
|
||||
})
|
||||
.flag({
|
||||
name: 'bool3',
|
||||
description: 'Ad consequat eiusmod officia aliqua. Eiusmod officia aliqua ',
|
||||
aliases: ['e22'],
|
||||
negatable: true,
|
||||
defaultValue: false,
|
||||
})
|
||||
.option({
|
||||
name: 'string',
|
||||
description:
|
||||
'Laborum qui ex do consectetur magna. Ex do consectetur magna officia, consequat. Magna officia consequat labore veniam proident exercitation occaecat. Consequat labore veniam proident exercitation occaecat. Veniam proident exercitation occaecat aliquip.',
|
||||
description: 'A string option',
|
||||
aliases: ['s'],
|
||||
})
|
||||
.option({
|
||||
@@ -141,8 +125,7 @@ const main = massarg<A>({
|
||||
.example({
|
||||
description: 'Example add command',
|
||||
input: 'my-cli add --component foo --classes bar --classes baz --custom 123',
|
||||
output:
|
||||
'Duis ad consectetur dolore elit laborum do et aute consequat magna eu consequat dolore dolor commodo sit enim reprehenderit lorem consectetur adipiscing officia nisi adipiscing consequat consequat labore sint incididunt',
|
||||
output: '42',
|
||||
})
|
||||
|
||||
// console.log("Opts:", main.getArgs(process.argv.slice(2)), "\n")
|
||||
|
||||
Reference in New Issue
Block a user