From dbbb12cd6a0a724e37655e6d49d1bb53b881dc8f Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Tue, 30 Jan 2024 02:26:16 +0200 Subject: [PATCH] fix: add spacing between args, update sample --- LICENSE | 2 +- README.md | 8 +++++--- src/help.ts | 16 +++++++--------- src/sample.ts | 25 ++++--------------------- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/LICENSE b/LICENSE index 51f3e2f..c7072aa 100644 --- a/LICENSE +++ b/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 diff --git a/README.md b/README.md index 2e99426..16e804a 100644 --- a/README.md +++ b/README.md @@ -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({ diff --git a/src/help.ts b/src/help.ts index bb909dc..653851d 100644 --- a/src/help.ts +++ b/src/help.ts @@ -423,7 +423,9 @@ function generateHelpTable 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({ .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({ 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({ .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")