Skip to content

Unexpected behavior when setting two std::vector values as positional arguments #457

@TrainFan1804

Description

@TrainFan1804

Description

I wanted set two std::vector options as positional arguments and tried following code:

options
    .add_options()
    ("f,foo", "foo", cxxopts::value<std::vector<std::string>>(), "foo")
    ("b,bar", "bar", cxxopts::value<std::vector<std::string>>(), "bar");

options.parse_positional({"foo", "bar"});

when I run

./a.out --bar a b c

I expected bar to be [a, b, c] and foo to be empty but I actually got.

bar = a
foo = b
foo = c

Expected

Non-option arguments following a option (--bar) should not be assigned as a positional parameter.

Conclusion

If this is desired behavior it would be helpful if it was clarified in the README.md.
If not I guess it may be a parsing bug.

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