| 433 | * @param completionMessage - Optional message to log when the command completes |
| 434 | * @returns A Command with integrated wrap functionality |
| 435 | */ |
| 436 | const makeCommandWithWrap = <Name extends string, const Config, R, E>( |
| 437 | name: Name, |
| 438 | config: Config, |
| 439 | handler: (_: any) => Effect.Effect<void, E, R>, |
| 440 | completionMessage?: string |
| 441 | ) => |
| 442 | Command.make( |
| 443 | name, |
| 444 | { ...config, wo: WrapAsOption, wa: WrapAsArg }, |
| 445 | Effect.fn("effa-cli.withWrapHandler")(function*(_) { |
| 446 | const { wa, wo, ...cfg } = _ as unknown as { |
| 447 | wo: Option.Option<string> |
| 448 | wa: Option.Option<ReadonlyArray<string>> |
| 449 | } |
| 450 | |
| 451 | if (completionMessage) { |
| 452 | yield* Effect.addFinalizer(() => Effect.logInfo(completionMessage)) |
| 453 | } |
| 454 | |
| 455 | const wrapOption = Option.orElse(wa, () => wo) |
| 456 | |
| 457 | yield* handler(cfg as any) |
| 458 | |
| 459 | if (Option.isSome(wrapOption)) { |
| 460 | const val: string = Array.isArray(wrapOption.value) |
| 461 | ? wrapOption.value.join(" ") |
| 462 | : wrapOption.value as string |
| 463 | |
| 464 | yield* Effect.logInfo(`Spawning child command: ${val}`) |
| 465 | const exitCode = yield* runGetExitCode(val) |
| 466 | if (exitCode !== 0) { |
| 467 | return yield* Effect.sync(() => process.exit(exitCode)) |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | return |
| 472 | }, (_) => Effect.scoped(_)) |
| 473 | ) |
| 474 | |
| 475 | const EffectAppLibsPath = Argument |