diff --git a/readme.md b/readme.md index d6a9eeb..6adf209 100644 --- a/readme.md +++ b/readme.md @@ -299,6 +299,13 @@ Default: `true` Whether to allow unknown flags or not. +##### helpIndent + +Type `number`\ +Default: `2` + +The number of spaces to use for indenting the help text. + ## Promises Meow will make unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail. Meaning you don't have to manually `.catch()` promises used in your CLI. diff --git a/source/index.d.ts b/source/index.d.ts index b7c240b..835cb7b 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -307,6 +307,13 @@ export type Options = { @default true */ readonly allowUnknownFlags?: boolean; + + /** + The number of spaces to use for indenting the help text. + + @default 2 + */ + readonly helpIndent?: number; }; type TypedFlag = diff --git a/source/index.js b/source/index.js index 3bc1865..b3ed67f 100644 --- a/source/index.js +++ b/source/index.js @@ -18,7 +18,7 @@ const buildResult = (options, parserOptions) => { help = trimNewlines((options.help || '').replace(/\t+\n*$/, '')); if (help.includes('\n')) { - help = redent(help, 2); + help = redent(help, options.helpIndent); } help = `\n${help}`; @@ -31,7 +31,7 @@ const buildResult = (options, parserOptions) => { ({description} = package_); } - description &&= help ? `\n ${description}\n` : `\n${description}`; + description &&= help ? redent(`\n${description}\n`, options.helpIndent) : `\n${description}`; help = `${description || ''}${help}\n`; const showHelp = code => { diff --git a/source/options.js b/source/options.js index 05169ef..98f032a 100644 --- a/source/options.js +++ b/source/options.js @@ -81,6 +81,7 @@ export const buildOptions = (helpText, options) => { hardRejection: true, allowUnknownFlags: true, allowParentFlags: true, + helpIndent: 2, ...options, }; diff --git a/test/help.js b/test/help.js index 7fd5492..c361c0a 100644 --- a/test/help.js +++ b/test/help.js @@ -44,3 +44,24 @@ test('descriptions with no help are not indented', t => { description: 'single line', }).help, '\nsingle line\n'); }); + +test('support help shortcut with no indentation', t => { + t.is(meow(` + unicorn + cat + `, { + helpIndent: 0, + importMeta, + }).help, indentString('\nCLI app helper\n\nunicorn\ncat\n', 0)); +}); + +test('no description and no indentation', t => { + t.is(meow(` + unicorn + cat + `, { + helpIndent: 0, + description: false, + importMeta, + }).help, indentString('\nunicorn\ncat\n', 0)); +});