Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide hidden options from completion #2143

Merged
merged 2 commits into from Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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