Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@effect/cli Options.repeated order of arguments matters #3729

Open
joepjoosten opened this issue Oct 4, 2024 · 1 comment · May be fixed by #3773
Open

@effect/cli Options.repeated order of arguments matters #3729

joepjoosten opened this issue Oct 4, 2024 · 1 comment · May be fixed by #3773
Labels
bug Something isn't working cli

Comments

@joepjoosten
Copy link
Contributor

joepjoosten commented Oct 4, 2024

What version of Effect is running?

effect 3.8.4, @effect/cli 0.45.2

What steps can reproduce the bug?

import { Console, Effect } from "effect";
import { NodeContext, NodeRuntime } from "@effect/platform-node";
import { Command, Options } from "@effect/cli";
 
const first = Options.text("first").pipe(Options.repeated);

const second = Options.text("second").pipe();

const third = Options.text("third").pipe();
 
const run = Command.make("example", { first, second, third }, (opts) =>
  Console.log(opts)
).pipe(
  Command.run({
    name: "Test",
    version: "1.0.0",
  })
);
 
const main = Effect.suspend(() => run(globalThis.process.argv));
 
main.pipe(
  Effect.provide(NodeContext.layer),
  Effect.tapErrorCause(Effect.logError),
  NodeRuntime.runMain
);

Then running it with the following options:
--third 3 --second 2 --first 1 --first 4, or
--first 1 --third 3 --second 2 --first 4
Wont work.

What is the expected behavior?

The order should not matter for the given options. (i know about sub commands, and there options / arguments must follow the sub command)

I expect it to work independent of the order, like non repeated options.

What do you see instead?

Error: {"_tag":"InvalidValue","error":{"_tag":"Paragraph","value":{"_tag":"Text","value":"Received unknown argument: '--first'"}}}

Additional information

No response

@joepjoosten joepjoosten added the bug Something isn't working label Oct 4, 2024
@joepjoosten joepjoosten changed the title Effect cli Options.repeated order of arguments matters @effect/cli Options.repeated order of arguments matters Oct 5, 2024
@gcanti gcanti added the cli label Oct 6, 2024
@joepjoosten joepjoosten linked a pull request Oct 11, 2024 that will close this issue
5 tasks
@joepjoosten
Copy link
Contributor Author

joepjoosten commented Oct 15, 2024

Is it my correct interpretation that effect cli reduces the Options? So it passes the leftover arguments to every Options in the iteration?

This way there is possible misinterpretation of arguments like when the arguments are like this:

I have two Options:
Options.text("t").pipe(Options.withDefault("default"))
Options.boolean("b")

Should this --t --b be interpretted as:

{
   t: "--b",
   b: false
}

or as

{
   t: "default",
   b: true
}

It now depends on the order in which the Options are evaluated.

Maybe it's better to do it the other way around: parse the args from left to right, and try see which Options fit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants