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

Function wizardInternal

packages/cli/src/internal/commandDescriptor.ts:872–965  ·  view source on GitHub ↗
(
  self: Instruction,
  prefix: ReadonlyArray<string>,
  config: CliConfig.CliConfig
)

Source from the content-addressed store, hash-verified

870const optionsWizardHeader = InternalSpan.code("Options Wizard - ")
871
872const wizardInternal = (
873 self: Instruction,
874 prefix: ReadonlyArray<string>,
875 config: CliConfig.CliConfig
876): Effect.Effect<
877 Array<string>,
878 Terminal.QuitException | ValidationError.ValidationError,
879 FileSystem.FileSystem | Path.Path | Terminal.Terminal
880> => {
881 const loop = (
882 self: Instruction,
883 commandLineRef: Ref.Ref<ReadonlyArray<string>>
884 ): Effect.Effect<
885 ReadonlyArray<string>,
886 Terminal.QuitException | ValidationError.ValidationError,
887 FileSystem.FileSystem | Path.Path | Terminal.Terminal
888 > => {
889 switch (self._tag) {
890 case "GetUserInput":
891 case "Standard": {
892 return Effect.gen(function*() {
893 const logCurrentCommand = Ref.get(commandLineRef).pipe(Effect.flatMap((commandLine) => {
894 const currentCommand = InternalHelpDoc.p(pipe(
895 InternalSpan.strong(InternalSpan.highlight("COMMAND:", Color.cyan)),
896 InternalSpan.concat(InternalSpan.space),
897 InternalSpan.concat(InternalSpan.highlight(
898 Arr.join(commandLine, " "),
899 Color.magenta
900 ))
901 ))
902 return Console.log(InternalHelpDoc.toAnsiText(currentCommand))
903 }))
904 if (isStandard(self)) {
905 // Log the current command line arguments
906 yield* logCurrentCommand
907 const commandName = InternalSpan.highlight(self.name, Color.magenta)
908 // If the command has options, run the wizard for them
909 if (!InternalOptions.isEmpty(self.options as InternalOptions.Instruction)) {
910 const message = InternalHelpDoc.p(
911 InternalSpan.concat(optionsWizardHeader, commandName)
912 )
913 yield* Console.log(InternalHelpDoc.toAnsiText(message))
914 const options = yield* InternalOptions.wizard(self.options, config)
915 yield* Ref.updateAndGet(commandLineRef, Arr.appendAll(options))
916 yield* logCurrentCommand
917 }
918 // If the command has args, run the wizard for them
919 if (!InternalArgs.isEmpty(self.args as InternalArgs.Instruction)) {
920 const message = InternalHelpDoc.p(
921 InternalSpan.concat(argsWizardHeader, commandName)
922 )
923 yield* Console.log(InternalHelpDoc.toAnsiText(message))
924 const options = yield* InternalArgs.wizard(self.args, config)
925 yield* Ref.updateAndGet(commandLineRef, Arr.appendAll(options))
926 yield* logCurrentCommand
927 }
928 }
929 return yield* Ref.get(commandLineRef)

Callers 1

Calls 4

loopFunction · 0.70
pipeMethod · 0.65
makeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected