* 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)
| 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.) |
no test coverage detected