Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ class Help {
extraInfo.push(`env: ${option.envVar}`);
}
if (extraInfo.length > 0) {
return `${option.description} (${extraInfo.join(', ')})`;
const extraDescription = `(${extraInfo.join(', ')})`;
if (option.description) {
return `${option.description} ${extraDescription}`;
}
return extraDescription;
}

return option.description;
Expand Down
12 changes: 12 additions & 0 deletions tests/help.optionDescription.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ describe('optionDescription', () => {
);
});

test('when option has default value but not description then return custom default', () => {
const defaultValueDescription = 'custom';
const option = new commander.Option('-a <value>').default(
'default value',
defaultValueDescription,
);
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual(
`(default: ${defaultValueDescription})`,
);
});

test('when option has choices then return description and choices', () => {
const description = 'description';
const choices = ['one', 'two'];
Expand Down