Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf37ee6f

Browse files
authored
fix: copy the description of the option to its alias in completion (#2269)
1 parent1fd530a commitf37ee6f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

‎lib/completion.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ export class Completion implements CompletionInstance {
258258
if(!this.zshShell){
259259
completions.push(dashes+key);
260260
}else{
261-
constdesc=descs[key]||'';
261+
constaliasKey=this?.aliases?.[key].find(alias=>{
262+
constdesc=descs[alias];
263+
returntypeofdesc==='string'&&desc.length>0;
264+
});
265+
constdescFromAlias=aliasKey ?descs[aliasKey] :undefined;
266+
constdesc=descs[key]??descFromAlias??'';
262267
completions.push(
263268
dashes+
264269
`${key.replace(/:/g,'\\:')}:${desc.replace('__yargsString__:','')}`

‎test/completion.cjs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,28 @@ describe('Completion', () => {
10551055
r.logs.should.include('--help:Show help');
10561056
});
10571057

1058+
it('completes options and aliases with the same description',()=>{
1059+
process.env.SHELL='/bin/zsh';
1060+
constr=checkUsage(
1061+
()=>
1062+
yargs(['./completion','--get-yargs-completions','-'])
1063+
.options({
1064+
foo:{describe:'Foo option',alias:'f',type:'string'},
1065+
bar:{describe:'Bar option',alias:['b','B'],type:'string'},
1066+
})
1067+
.help(false)
1068+
.version(false)
1069+
.completion().argv
1070+
);
1071+
1072+
r.logs.should.have.length(5);
1073+
r.logs.should.include('--foo:Foo option');
1074+
r.logs.should.include('-f:Foo option');
1075+
r.logs.should.include('--bar:Bar option');
1076+
r.logs.should.include('-b:Bar option');
1077+
r.logs.should.include('-B:Bar option');
1078+
});
1079+
10581080
it('replaces application variable with $0 in script',()=>{
10591081
process.env.SHELL='/bin/zsh';
10601082
constr=checkUsage(()=>yargs([]).showCompletionScript(),['ndm']);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp