( command: Command<Name, Input, ContextInput, E, R>, commandPath: ReadonlyArray<string>, builtIns: ReadonlyArray<GlobalFlag.GlobalFlag<any>> )
| 150 | * Reads active global flags for the path and includes them in the help doc. |
| 151 | */ |
| 152 | export const getHelpForCommandPath = <Name extends string, Input, E, R, ContextInput>( |
| 153 | command: Command<Name, Input, ContextInput, E, R>, |
| 154 | commandPath: ReadonlyArray<string>, |
| 155 | builtIns: ReadonlyArray<GlobalFlag.GlobalFlag<any>> |
| 156 | ): Effect.Effect<HelpDoc, never, never> => |
| 157 | Effect.gen(function*() { |
| 158 | const commands = getCommandsForCommandPath(command, commandPath) |
| 159 | const currentCommand = commands.length > 0 ? commands[commands.length - 1] : command |
| 160 | |
| 161 | const baseDoc = toImpl(currentCommand).buildHelpDoc(commandPath) |
| 162 | |
| 163 | const sharedFlags = getSharedFlagsForCommandPath(commands, baseDoc.flags) |
| 164 | |
| 165 | const flags = getGlobalFlagsForCommandPath(command, commandPath, builtIns) |
| 166 | const globalFlagDocs: Array<FlagDoc> = [] |
| 167 | for (const flag of flags) { |
| 168 | const singles = Param.extractSingleParams(flag.flag) |
| 169 | const metadata = Param.getParamMetadata(flag.flag) |
| 170 | for (const single of singles) { |
| 171 | // Same rule as command-local flags: hidden globals are still parsed |
| 172 | // and still trigger their handlers, they just don't appear under |
| 173 | // "GLOBAL FLAGS" in --help. |
| 174 | if (single.hidden) continue |
| 175 | globalFlagDocs.push({ |
| 176 | ...toFlagDoc(single, metadata), |
| 177 | required: false |
| 178 | }) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return { ...baseDoc, flags: [...sharedFlags, ...baseDoc.flags], globalFlags: globalFlagDocs } |
| 183 | }) |
no test coverage detected