Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap(null) no longer causes strange indentation behavior #1988

Merged
merged 5 commits into from Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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