MCPcopy Create free account
hub / github.com/Effect-TS/effect / getHelpForCommandPath

Function getHelpForCommandPath

packages/effect/src/cli/internal/help.ts:150–196  ·  view source on GitHub ↗
(
  command: Command<Name, Input, ContextInput, E, R>,
  commandPath: ReadonlyArray<string>,
  builtIns: ReadonlyArray<GlobalFlag.GlobalFlag<any>>
)

Source from the content-addressed store, hash-verified

148 * Reads active global flags for the path and includes them in the help doc.
149 */
150export const getHelpForCommandPath = <Name extends string, Input, E, R, ContextInput>(
151 command: Command<Name, Input, ContextInput, E, R>,
152 commandPath: ReadonlyArray<string>,
153 builtIns: ReadonlyArray<GlobalFlag.GlobalFlag<any>>
154): Effect.Effect<HelpDoc, never, never> =>
155 Effect.gen(function*() {
156 const commands = getCommandsForCommandPath(command, commandPath)
157 const currentCommand = commands.length > 0 ? commands[commands.length - 1] : command
158
159 const baseDoc = toImpl(currentCommand).buildHelpDoc(commandPath)
160
161 const inheritedFlags = getInheritedFlagsForCommandPath(commands, baseDoc.flags)
162
163 const flags = getGlobalFlagsForCommandPath(command, commandPath, builtIns)
164 const globalFlagDocs: Array<FlagDoc> = []
165 for (const flag of flags) {
166 const singles = Param.extractSingleParams(flag.flag)
167 const metadata = Param.getParamMetadata(flag.flag)
168 for (const single of singles) {
169 // Same rule as command-local flags: hidden globals are still parsed
170 // and still trigger their handlers, they just don't appear under
171 // "GLOBAL FLAGS" in --help.
172 if (single.hidden) continue
173 globalFlagDocs.push({
174 ...toFlagDoc(single, metadata),
175 required: false
176 })
177 }
178 }
179
180 // Globals accumulate along the path, so the deepest declaring scope lists them all.
181 let scopeLength = 1
182 for (let i = commands.length - 1; i > 0; i--) {
183 if (toImpl(commands[i]).globalFlags.length > 0) {
184 scopeLength = i + 1
185 break
186 }
187 }
188
189 return {
190 ...baseDoc,
191 inheritedFlags,
192 globalFlags: globalFlagDocs,
193 globalFlagsScope: commandPath.slice(0, scopeLength),
194 commandPath
195 }
196 })

Callers 1

showHelpFunction · 0.90

Calls 7

toImplFunction · 0.90
toFlagDocFunction · 0.90
sliceMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected