From 4cb41dc80aaa730a2abd15bd3118ecd9f4ebe876 Mon Sep 17 00:00:00 2001 From: Nguyen Thai Hung <59815499+hung-cybo@users.noreply.github.com> Date: Tue, 14 Feb 2023 00:50:28 +0700 Subject: [PATCH] feat: convert line break to whitespace for the description of the option (#2271) Co-authored-by: Benjamin E. Coe --- lib/completion.ts | 4 +++- test/completion.cjs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/completion.ts b/lib/completion.ts index 00c8ea5f2..73c12c177 100644 --- a/lib/completion.ts +++ b/lib/completion.ts @@ -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, ' ')}` ); } } diff --git a/test/completion.cjs b/test/completion.cjs index 002bff75f..4e2d6bef0 100644 --- a/test/completion.cjs +++ b/test/completion.cjs @@ -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']);