MCPcopy
hub / github.com/Effect-TS/effect / handleBuiltInOption

Function handleBuiltInOption

packages/cli/src/internal/cliApp.ts:149–301  ·  view source on GitHub ↗
(
  self: CliApp.CliApp<A>,
  executable: string,
  args: ReadonlyArray<string>,
  builtIn: BuiltInOptions.BuiltInOptions,
  execute: (a: A) => Effect.Effect<void, E, R>,
  config: CliConfig.CliConfig,
  originalArgs: ReadonlyArray<string>
)

Source from the content-addressed store, hash-verified

147const printDocs = (error: HelpDoc.HelpDoc): Effect.Effect<void> => Console.error(InternalHelpDoc.toAnsiText(error))
148
149const handleBuiltInOption = <R, E, A>(
150 self: CliApp.CliApp<A>,
151 executable: string,
152 args: ReadonlyArray<string>,
153 builtIn: BuiltInOptions.BuiltInOptions,
154 execute: (a: A) => Effect.Effect<void, E, R>,
155 config: CliConfig.CliConfig,
156 originalArgs: ReadonlyArray<string>
157): Effect.Effect<
158 void,
159 E | ValidationError.ValidationError,
160 R | CliApp.CliApp.Environment | Terminal.Terminal
161> => {
162 switch (builtIn._tag) {
163 case "SetLogLevel": {
164 // Use first 2 elements from originalArgs (runtime + script) to preserve paths with spaces
165 // Filter out --log-level from args before re-executing
166 const baseArgs = Arr.take(originalArgs, 2)
167 const filteredArgs: Array<string> = []
168 for (let i = 0; i < args.length; i++) {
169 if (isLogLevelArg(args[i]) || args[i - 1] === "--log-level") {
170 continue
171 }
172 filteredArgs.push(args[i])
173 }
174 const nextArgs = Arr.appendAll(baseArgs, filteredArgs)
175 return run(self, nextArgs, execute).pipe(
176 Logger.withMinimumLogLevel(builtIn.level)
177 )
178 }
179 case "ShowHelp": {
180 const banner = InternalHelpDoc.h1(InternalSpan.code(self.name))
181 const header = InternalHelpDoc.p(InternalSpan.spans([
182 InternalSpan.text(`${self.name} ${self.version}`),
183 InternalSpan.isEmpty(self.summary)
184 ? InternalSpan.empty
185 : InternalSpan.spans([
186 InternalSpan.space,
187 InternalSpan.text("--"),
188 InternalSpan.space,
189 self.summary
190 ])
191 ]))
192 const usage = InternalHelpDoc.sequence(
193 InternalHelpDoc.h1("USAGE"),
194 pipe(
195 InternalUsage.enumerate(builtIn.usage, config),
196 Arr.map((span) => InternalHelpDoc.p(InternalSpan.concat(InternalSpan.text("$ "), span))),
197 Arr.reduceRight(
198 InternalHelpDoc.empty,
199 (left, right) => InternalHelpDoc.sequence(left, right)
200 )
201 )
202 )
203 const helpDoc = pipe(
204 banner,
205 InternalHelpDoc.sequence(header),
206 InternalHelpDoc.sequence(usage),

Callers 1

cliApp.tsFile · 0.85

Calls 14

isLogLevelArgFunction · 0.85
getWizardPrefixFunction · 0.85
renderWizardArgsFunction · 0.85
pipeFunction · 0.70
takeMethod · 0.65
pipeMethod · 0.65
isEmptyMethod · 0.65
mapMethod · 0.65
logMethod · 0.65
joinMethod · 0.65
errorMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected