diff --git a/readme.md b/readme.md index 6e6146f..7f51362 100644 --- a/readme.md +++ b/readme.md @@ -292,6 +292,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 427e1ae..5fa3b34 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -309,6 +309,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 e71aaad..bd048c3 100644 --- a/source/index.js +++ b/source/index.js @@ -17,7 +17,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}`; @@ -30,7 +30,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 8a331cf..d46d317 100644 --- a/source/options.js +++ b/source/options.js @@ -80,6 +80,7 @@ export const buildOptions = (helpText, options) => { booleanDefault: false, 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)); +});