Lyra icon indicating copy to clipboard operation
Lyra copied to clipboard

coalesced flags with final one being an option don't work

Open wreedb opened this issue 1 month ago • 0 comments

using namespace lyra;

bool fooinvoked = false;
bool showfoohelp = false;
bool showhelp = false;
bool verbose = false;
bool dryrun = false;
std::string name;

auto cli
    = help(showhelp)
    | command("foo", [&](const group&) { foo_invoked = true; })
        .add_argument(help(showfoohelp))
        .add_argument(opt(verbose)["-v"]["--verbose"]("display more output").optional())
        .add_argument(opt(dryrun)["-d"]["--dry-run"]("simulate actions").optional())
        .add_argument(opt(name, "NAME")["-n"]["--name"]("specify a name").optional());


auto result = cli.parse({argc,argv});

if (fooinvoked) {
    if (!name.empty()) std::cout << "name: " << name << "\n";
    std::cout << "verbose: " << verbose << "\n";
    std::cout << "dryrun: " << dryrun << std::endl;
}

given the above snippet, running:

./demo -vdn foo

does not work; 'foo' becomes an unexpected token, but:

./demo -vd -n foo

works still; the coalescing works perfectly, unless the final option takes a value.

I've been considering replacing CLI11 in my project with Lyra, however this caught me in my tracks; is this intentional behavior?

wreedb avatar Nov 22 '25 00:11 wreedb