Skip to content

Using optional args out of order leads to wrong values all around #148

Open
@ericonr

Description

#include "docopt.h"
#include <iostream>

static const char usage[] =
R"(Usage:
    order [-t <vt> -C <vc>]

Options:
-t <vt>  T val
-C <vc>  C val
)";

int main(int argc, char *argv[])
{
    std::map<std::string, docopt::value> args = docopt::docopt(usage, {argv+1, argv+argc}, true);

    for(auto const& arg : args) {
        std::cout << arg.first << ": " << arg.second << std::endl;
    }
}

In same order as the help string (correct):

./order -t 0 -C 1
-C: true
-t: true
<vc>: "1"
<vt>: "0"

In opposite order (wrong):

./order -C 0 -t 1
-C: true
-t: true
<vc>: "1"
<vt>: "0"

Only the first one (correct):

./order -t 0
-C: false
-t: true
<vc>: null
<vt>: "0"

Only the second one (wrong):

./order -C 0
-C: true
-t: false
<vc>: null
<vt>: "0"

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions