MCPcopy
hub / github.com/tj/commander.js / visibleOptions

Method visibleOptions

lib/help.js:80–104  ·  view source on GitHub ↗

* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. * * @param {Command} cmd * @returns {Option[]}

(cmd)

Source from the content-addressed store, hash-verified

78 */
79
80 visibleOptions(cmd) {
81 const visibleOptions = cmd.options.filter((option) => !option.hidden);
82 // Built-in help option.
83 const helpOption = cmd._getHelpOption();
84 if (helpOption && !helpOption.hidden) {
85 // Automatically hide conflicting flags. Bit dubious but a historical behaviour that is convenient for single-command programs.
86 const removeShort = helpOption.short && cmd._findOption(helpOption.short);
87 const removeLong = helpOption.long && cmd._findOption(helpOption.long);
88 if (!removeShort && !removeLong) {
89 visibleOptions.push(helpOption); // no changes needed
90 } else if (helpOption.long && !removeLong) {
91 visibleOptions.push(
92 cmd.createOption(helpOption.long, helpOption.description),
93 );
94 } else if (helpOption.short && !removeShort) {
95 visibleOptions.push(
96 cmd.createOption(helpOption.short, helpOption.description),
97 );
98 }
99 }
100 if (this.sortOptions) {
101 visibleOptions.sort(this.compareOptions);
102 }
103 return visibleOptions;
104 }
105
106 /**
107 * Get an array of the visible global options. (Not including help.)

Callers 7

unknownOptionMethod · 0.80
formatHelpMethod · 0.80
index.test-d.tsFile · 0.80

Calls 3

_getHelpOptionMethod · 0.80
_findOptionMethod · 0.80
createOptionMethod · 0.45

Tested by

no test coverage detected