From 08b71a0764f1e6d0efb36e19464b7ffe016f40ca Mon Sep 17 00:00:00 2001 From: Nguyen Thai Hung Date: Sun, 27 Nov 2022 10:22:02 +0700 Subject: [PATCH] feat: convert line break to whitespace for the description of the option --- 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 d8d84f01c..13c6f0d08 100644 --- a/lib/completion.ts +++ b/lib/completion.ts @@ -261,7 +261,9 @@ export class Completion implements CompletionInstance { const desc = descs[key] || ''; 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 ff7027121..7d7e4508d 100644 --- a/test/completion.cjs +++ b/test/completion.cjs @@ -1055,6 +1055,23 @@ describe('Completion', () => { r.logs.should.include('--help:Show help'); }); + 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']);