diff --git a/lib/completion.ts b/lib/completion.ts index 997d062ad..42f4c2d49 100644 --- a/lib/completion.ts +++ b/lib/completion.ts @@ -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); diff --git a/test/completion.cjs b/test/completion.cjs index 498c57073..6dc6868ee 100644 --- a/test/completion.cjs +++ b/test/completion.cjs @@ -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';