Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4cb41dc

Browse files
hung-cyboBenjamin E. Coe
andauthored
feat: convert line break to whitespace for the description of the option (#2271)
Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent 7dc1086 commit 4cb41dc

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/completion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ export class Completion implements CompletionInstance {
266266
const desc = descs[key] ?? descFromAlias ?? '';
267267
completions.push(
268268
dashes +
269-
`${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`
269+
`${key.replace(/:/g, '\\:')}:${desc
270+
.replace('__yargsString__:', '')
271+
.replace(/(\r\n|\n|\r)/gm, ' ')}`
270272
);
271273
}
272274
}

test/completion.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,23 @@ describe('Completion', () => {
10771077
r.logs.should.include('-B:Bar option');
10781078
});
10791079

1080+
it('completes options with line break', () => {
1081+
process.env.SHELL = '/bin/zsh';
1082+
const r = checkUsage(
1083+
() =>
1084+
yargs(['./completion', '--get-yargs-completions', '-'])
1085+
.options({
1086+
foo: {describe: 'Foo option\nFoo option', type: 'string'},
1087+
})
1088+
.help(false)
1089+
.version(false)
1090+
.completion().argv
1091+
);
1092+
1093+
r.logs.should.have.length(1);
1094+
r.logs.should.include('--foo:Foo option Foo option');
1095+
});
1096+
10801097
it('replaces application variable with $0 in script', () => {
10811098
process.env.SHELL = '/bin/zsh';
10821099
const r = checkUsage(() => yargs([]).showCompletionScript(), ['ndm']);

0 commit comments

Comments
 (0)