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

Question on how to return error in lyra::opt lambdas #69

Closed schoetbi closed 2 years ago

schoetbi commented 2 years ago

I like to return an error if parsing of an argument inside a lambda expression fails. Is there such an option? How can I return an error if the parsing fails, in this case if the IP address is invalid?

lyra::opt([&](const std::string& ip_string) {
      bool success = cmdpara.SourceIpAddress(ip_string);
      return success;
    }, "ip  address ")
      ["-i"]
      ["--ip_address"]
      ("address virtual nic rtx side (default localhost)"));
schoetbi commented 2 years ago

I found the coice option. This should work.

https://github.com/bfgroup/Lyra/blob/develop/examples/doc_example6.cpp#L18