Skip to content

Commit

Permalink
Don't indent single line help / description text (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell authored Mar 28, 2023
1 parent b2d7ce7 commit a5d15e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ const meow = (helpText, options = {}) => {

const {pkg: package_} = options;
const argv = parseArguments(options.argv, parserOptions);
let help = redent(trimNewlines((options.help ?? '').replace(/\t+\n*$/, '')), 2);
let help = trimNewlines((options.help || '').replace(/\t+\n*$/, ''));

if (help.includes('\n')) {
help = redent(help, 2);
}

normalizePackageData(package_);

Expand All @@ -295,7 +299,12 @@ const meow = (helpText, options = {}) => {
({description} = package_);
}

help = (description ? `\n ${description}\n` : '') + (help ? `\n${help}\n` : '\n');
// Change to `&&=` when targeting Node 15+
if (description) {
description = help ? `\n ${description}\n` : `\n${description}`;
}

help = (description || '') + (help ? `\n${help}\n` : '\n');

const showHelp = code => {
console.log(help);
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,26 @@ test('options - multiple validation errors', t => {
`});
});

test('single line help messages are not indented', t => {
const cli = meow({
importMeta,
description: false,
help: 'single line',
});

t.is(cli.help, '\nsingle line\n');
});

test('descriptions with no help are not indented', t => {
const cli = meow({
importMeta,
help: false,
description: 'single line',
});

t.is(cli.help, '\nsingle line\n');
});

if (NODE_MAJOR_VERSION >= 14) {
test('supports es modules', async t => {
try {
Expand Down

0 comments on commit a5d15e8

Please sign in to comment.