Skip to content

Commit 4fb4747

Browse files
committed
Remove support for shadowing help flags
1 parent 1d0fe63 commit 4fb4747

File tree

3 files changed

+36
-45
lines changed

3 files changed

+36
-45
lines changed

lib/help.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,7 @@ class Help {
7171
// Built-in help option.
7272
const helpOption = cmd._getHelpOption();
7373
if (helpOption && !helpOption.hidden) {
74-
// Automatically hide conflicting flags. (Bit magical and messy, but preserve for now!)
75-
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
76-
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
77-
if (!removeShort && !removeLong) {
78-
visibleOptions.push(helpOption); // no changes needed
79-
} else if (helpOption.long && !removeLong) {
80-
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
81-
} else if (helpOption.short && !removeShort) {
82-
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
83-
}
74+
visibleOptions.push(helpOption);
8475
}
8576
if (this.sortOptions) {
8677
visibleOptions.sort(this.compareOptions);

tests/command.help.test.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ test('when addCommand with hidden:true then not displayed in helpInformation', (
121121
expect(helpInformation).not.toMatch('secret');
122122
});
123123

124-
test('when help short flag masked then not displayed in helpInformation', () => {
125-
const program = new commander.Command();
126-
program
127-
.option('-h, --host', 'select host');
128-
const helpInformation = program.helpInformation();
129-
expect(helpInformation).not.toMatch(/\W-h\W.*display help/);
130-
});
131-
132-
test('when both help flags masked then not displayed in helpInformation', () => {
133-
const program = new commander.Command();
134-
program
135-
.option('-h, --help', 'custom');
136-
const helpInformation = program.helpInformation();
137-
expect(helpInformation).not.toMatch('display help');
138-
});
124+
// test('when help short flag masked then not displayed in helpInformation', () => {
125+
// const program = new commander.Command();
126+
// program
127+
// .option('-h, --host', 'select host');
128+
// const helpInformation = program.helpInformation();
129+
// expect(helpInformation).not.toMatch(/\W-h\W.*display help/);
130+
// });
131+
132+
// test('when both help flags masked then not displayed in helpInformation', () => {
133+
// const program = new commander.Command();
134+
// program
135+
// .option('-h, --help', 'custom');
136+
// const helpInformation = program.helpInformation();
137+
// expect(helpInformation).not.toMatch('display help');
138+
// });
139139

140140
test('when call .help then output on stdout', () => {
141141
const writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => { });

tests/help.visibleOptions.test.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ describe('implicit help', () => {
4545
expect(helper.optionTerm(implicitHelp)).toEqual('-h, --help');
4646
});
4747

48-
test('when short flag obscured then help term is --help', () => {
49-
const program = new commander.Command();
50-
program.addOption(new commander.Option('-h, --huge').hideHelp());
51-
const helper = new commander.Help();
52-
const implicitHelp = helper.visibleOptions(program)[0];
53-
expect(helper.optionTerm(implicitHelp)).toEqual('--help');
54-
});
48+
// test('when short flag obscured then help term is --help', () => {
49+
// const program = new commander.Command();
50+
// program.addOption(new commander.Option('-h, --huge').hideHelp());
51+
// const helper = new commander.Help();
52+
// const implicitHelp = helper.visibleOptions(program)[0];
53+
// expect(helper.optionTerm(implicitHelp)).toEqual('--help');
54+
// });
5555

56-
test('when long flag obscured then help term is --h', () => {
57-
const program = new commander.Command();
58-
program.addOption(new commander.Option('-H, --help').hideHelp());
59-
const helper = new commander.Help();
60-
const implicitHelp = helper.visibleOptions(program)[0];
61-
expect(helper.optionTerm(implicitHelp)).toEqual('-h');
62-
});
56+
// test('when long flag obscured then help term is --h', () => {
57+
// const program = new commander.Command();
58+
// program.addOption(new commander.Option('-H, --help').hideHelp());
59+
// const helper = new commander.Help();
60+
// const implicitHelp = helper.visibleOptions(program)[0];
61+
// expect(helper.optionTerm(implicitHelp)).toEqual('-h');
62+
// });
6363

64-
test('when help flags obscured then implicit help hidden', () => {
65-
const program = new commander.Command();
66-
program.addOption(new commander.Option('-h, --help').hideHelp());
67-
const helper = new commander.Help();
68-
expect(helper.visibleOptions(program)).toEqual([]);
69-
});
64+
// test('when help flags obscured then implicit help hidden', () => {
65+
// const program = new commander.Command();
66+
// program.addOption(new commander.Option('-h, --help').hideHelp());
67+
// const helper = new commander.Help();
68+
// expect(helper.visibleOptions(program)).toEqual([]);
69+
// });
7070
});

0 commit comments

Comments
 (0)