Effect CommunityEC
Effect Community2y ago
6 replies
whatplan

Troubleshooting 'Options.repeated' Issue

Im having some issues and ive narrowed it done to Options.repeated
import { Console, Effect } from "effect";
import { BunContext, Runtime } from "@effect/platform-bun";
import { Command, Options } from "@effect/cli";

const repeatedOption = Options.text("repeat").pipe(Options.repeated);

const run = Command.make("test", { repeatedOption }, (args) =>
  Console.log(args)
).pipe(
  Command.run({
    name: "Test",
    version: "1.0.0",
  })
);

const main = Effect.suspend(() => run(globalThis.process.argv));

main.pipe(
  Effect.provide(BunContext.layer),
  Effect.tapErrorCause(Effect.logError),
  Runtime.runMain
);


when run with the option, things work as expected:
$ tsx test.ts --repeat one --repeat two
{ repeatedOption: [ 'one', 'two' ] }


but when no other options or args are included, things also work as expected
$ tsx test.ts 
Expected to find option: '--repeat'

timestamp=2024-01-25T02:28:43.129Z level=ERROR fiber=#12 cause="Error: {\"_tag\":\"MissingValue\",\"error\":{\"_tag\":\"Paragraph\",\"value\":{\"_tag\":\"Text\",\"value\":\"Expected to find option: '--repeat'\"}}}"
timestamp=2024-01-25T02:28:43.130Z level=ERROR fiber=#12 cause="Error: {\"_tag\":\"MissingValue\",\"error\":{\"_tag\":\"Paragraph\",\"value\":{\"_tag\":\"Text\",\"value\":\"Expected to find option: '--repeat'\"}}}"
Was this page helpful?