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

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

Open
mknejp opened this issue Jun 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mknejp
Copy link

mknejp commented Jun 3, 2024

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
Copy link

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.

@grafikrobot grafikrobot added the bug Something isn't working label Sep 23, 2024
@grafikrobot grafikrobot moved this to 🔖 Ready in BFG Tasks Sep 23, 2024
@jpyllman
Copy link

I do not know what the best solution is. I know to little of the parser. But I guess just having a 'global' flag to tell you not to allow more then one command.

@jpyllman
Copy link

Another thing. Does the parser know to group the command specific options. So options does not spill over between the commands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🔖 Ready
Development

No branches or pull requests

4 participants