Skip to content

Commit

Permalink
feat: convert line break to whitespace for the description of the opt…
Browse files Browse the repository at this point in the history
…ion (#2271)

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
hung-cybo and bcoe committed Feb 13, 2023
1 parent 7dc1086 commit 4cb41dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/completion.ts
Expand Up @@ -266,7 +266,9 @@ export class Completion implements CompletionInstance {
const desc = descs[key] ?? descFromAlias ?? '';
completions.push(
dashes +
`${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`
`${key.replace(/:/g, '\\:')}:${desc
.replace('__yargsString__:', '')
.replace(/(\r\n|\n|\r)/gm, ' ')}`
);
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/completion.cjs
Expand Up @@ -1077,6 +1077,23 @@ describe('Completion', () => {
r.logs.should.include('-B:Bar option');
});

it('completes options with line break', () => {
process.env.SHELL = '/bin/zsh';
const r = checkUsage(
() =>
yargs(['./completion', '--get-yargs-completions', '-'])
.options({
foo: {describe: 'Foo option\nFoo option', type: 'string'},
})
.help(false)
.version(false)
.completion().argv
);

r.logs.should.have.length(1);
r.logs.should.include('--foo:Foo option Foo option');
});

it('replaces application variable with $0 in script', () => {
process.env.SHELL = '/bin/zsh';
const r = checkUsage(() => yargs([]).showCompletionScript(), ['ndm']);
Expand Down

0 comments on commit 4cb41dc

Please sign in to comment.