Lyra icon indicating copy to clipboard operation
Lyra copied to clipboard

Multiple commands declared at the same level are parsed and executed in sequence

Open mknejp opened this issue 8 months ago • 3 comments

When one defines multiple commands at the same level

cli.add_argument(
  lyra::command("foo", [&](lyra::group const& g) { fmt::println("running foo"); })
);
cli.add_argument(
  lyra::command("bar", [&](lyra::group const& g) { fmt::println("running bar"); })
);

Then the following invocation exec foo bar prints

running foo
running bar

I think the expectation here is that only one command is recognized and the other rejected as a syntax error.

Note that this differs from nesting commands like this

cli.add_argument(
  lyra::command("foo", [&](lyra::group const& g) { fmt::println("running foo"); })
    .add_argument(
      lyra::command("bar", [&](lyra::group const& g) { fmt::println("running bar"); })
    )
);

Which when invoked with exec foo bar prints

running bar
running foo

And works as expected.

mknejp avatar Jun 03 '24 14:06 mknejp