Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: wrap(null) no longer causes strange indentation behavior (#1988)
  • Loading branch information
OsmanAltun committed Aug 4, 2021
1 parent b737d68 commit e1871aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/usage.ts
Expand Up @@ -206,7 +206,7 @@ export function usage(yargs: YargsInstance, shim: PlatformShim) {
if (usages.length) {
// user-defined usage.
usages.forEach(usage => {
ui.div(`${usage[0].replace(/\$0/g, base$0)}`);
ui.div({text: `${usage[0].replace(/\$0/g, base$0)}`});
if (usage[1]) {
ui.div({text: `${usage[1]}`, padding: [1, 0, 0, 0]});
}
Expand Down
26 changes: 26 additions & 0 deletions test/usage.cjs
Expand Up @@ -1884,6 +1884,32 @@ describe('usage tests', () => {
' -h, --help Show help [boolean]',
]);
});

it('should not indent usage when no wrap is specified', () => {
const expected = [
' My greatest CLI App',
'Hello, world',
'',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
];

const r = checkUsage(() =>
yargs('--help')
.usage(
[
' My greatest CLI App',
'Hello, world',
].join('\n')
)
.wrap(null)
.parse()
);

// the leading whitespaces on the first line should not cause indentation to usage string
r.logs[0].split('\n').should.deep.equal(expected);
});
});

describe('commands', () => {
Expand Down

0 comments on commit e1871aa

Please sign in to comment.