Skip to content

Multiple commands problem - use one_of instead of | #60

@WojciechMigda

Description

@WojciechMigda

Hi,

some time ago I stumbled upon a problem with CLI, which consisted of three or more commands. I have found a work-around and I am posting it here hoping it will help others struggling with the same.

The smallest non-working example is:

    auto cli = (
        command("a").set(m.a) |
        command("b").set(m.b) |
        (
            command("c").set(m.c) & value("i", m.i)
        )
    );

where clipp would parse a, b, but not c 123.

It turned out that I can make clipp do what I want if instead of specifying the alternative of commands with | I'd use clipp::one_of.
The example above becomes:

    auto cli = one_of(
        command("a").set(m.a),
        command("b").set(m.b),
        command("c").set(m.c) & value("i", m.i)
    );

The docs, unless I am missing something, specify that one_of is the same as |, yet they produce different usage lines. The first one gives

((a|b) | (c <i>))

while the second one

(a | b | (c <i>))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions