Skip to content

Commit e9a55cd

Browse files
Add helpIndent option (#241)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent fd0bc62 commit e9a55cd

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ Default: `true`
292292

293293
Whether to allow unknown flags or not.
294294

295+
##### helpIndent
296+
297+
Type `number`\
298+
Default: `2`
299+
300+
The number of spaces to use for indenting the help text.
301+
295302
## Promises
296303

297304
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.

source/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ export type Options<Flags extends AnyFlags> = {
309309
@default true
310310
*/
311311
readonly allowUnknownFlags?: boolean;
312+
313+
/**
314+
The number of spaces to use for indenting the help text.
315+
316+
@default 2
317+
*/
318+
readonly helpIndent?: number;
312319
};
313320

314321
type TypedFlag<Flag extends AnyFlag> =

source/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const buildResult = (options, parserOptions) => {
1717
help = trimNewlines((options.help || '').replace(/\t+\n*$/, ''));
1818

1919
if (help.includes('\n')) {
20-
help = redent(help, 2);
20+
help = redent(help, options.helpIndent);
2121
}
2222

2323
help = `\n${help}`;
@@ -30,7 +30,7 @@ const buildResult = (options, parserOptions) => {
3030
({description} = package_);
3131
}
3232

33-
description &&= help ? `\n ${description}\n` : `\n${description}`;
33+
description &&= help ? redent(`\n${description}\n`, options.helpIndent) : `\n${description}`;
3434
help = `${description || ''}${help}\n`;
3535

3636
const showHelp = code => {

source/options.js

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const buildOptions = (helpText, options) => {
8080
booleanDefault: false,
8181
allowUnknownFlags: true,
8282
allowParentFlags: true,
83+
helpIndent: 2,
8384
...options,
8485
};
8586

test/help.js

+21
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,24 @@ test('descriptions with no help are not indented', t => {
4444
description: 'single line',
4545
}).help, '\nsingle line\n');
4646
});
47+
48+
test('support help shortcut with no indentation', t => {
49+
t.is(meow(`
50+
unicorn
51+
cat
52+
`, {
53+
helpIndent: 0,
54+
importMeta,
55+
}).help, indentString('\nCLI app helper\n\nunicorn\ncat\n', 0));
56+
});
57+
58+
test('no description and no indentation', t => {
59+
t.is(meow(`
60+
unicorn
61+
cat
62+
`, {
63+
helpIndent: 0,
64+
description: false,
65+
importMeta,
66+
}).help, indentString('\nunicorn\ncat\n', 0));
67+
});

0 commit comments

Comments
 (0)