Skip to content

Commit

Permalink
fix: hide hidden options from completion (#2143)
Browse files Browse the repository at this point in the history
Fixes: #2142

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
alan-agius4 and bcoe committed Mar 19, 2022
1 parent bcd59f1 commit e086dfa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/completion.ts
Expand Up @@ -127,6 +127,7 @@ export class Completion implements CompletionInstance {
// If the key is not positional and its aliases aren't in 'args', add the key to 'completions'
if (
!isPositionalKey &&
!options.hiddenOptions.includes(key) &&
!this.argsContainKey(args, argv, key, negable)
) {
this.completeOptionKey(key, completions, current);
Expand Down
28 changes: 28 additions & 0 deletions test/completion.cjs
Expand Up @@ -813,6 +813,34 @@ describe('Completion', () => {
r.logs.should.include('--help');
});

it('does not complete hidden options for command', () => {
process.env.SHELL = '/bin/bash';
const r = checkUsage(
() =>
yargs(['./completion', '--get-yargs-completions', 'foo', '--b'])
.command('foo', 'foo command', subYargs =>
subYargs
.options({
bar: {
describe: 'bar option',
},
buz: {
describe: 'buz option',
hidden: true,
},
})
.help(true)
.version(false)
)
.completion().argv
);

r.logs.should.have.length(2);
r.logs.should.include('--bar');
r.logs.should.not.include('--buz');
r.logs.should.include('--help');
});

describe('generateCompletionScript()', () => {
it('replaces application variable with $0 in script', () => {
process.env.SHELL = '/bin/bash';
Expand Down

0 comments on commit e086dfa

Please sign in to comment.