bfgroup / Lyra

A simple to use, composable, command line parser for C++ 11 and beyond
https://bfgroup.github.io/Lyra/
Boost Software License 1.0
471 stars 56 forks source link

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

Open mknejp opened 3 months ago

mknejp commented 3 months ago

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.

akoutian commented 1 month ago

I second this. I have not yet seen any command line tool that allows multiple subcommands to be executed. Usually it's just one, and any following ones are discarded. Common examples are conan, cryptsetup and cargo.