Skip to content

Option needs an another one with a given value #806

Answered by phlptp
wsbak asked this question in Q&A
Discussion options

You must be logged in to vote
TEST_CASE_METHOD(TApp, "NeedsTrue", "[app]") {
    std::string str;
    CLI::Option *opts = app.add_option("-s,--string", str);
    app.add_flag("--opt1")->check([&](const std::string &) {
         return (str != "val_with_opt1")?std::string("--opt1 requires --string val_with_opt1"):std::string{};
});

    run();

    args = {"--opt1"};
    CHECK_THROWS_AS(run(), CLI::ValidationError);

    args = {"--string", "val"};
    run();

    args = {"--string", "val", "--opt1"};
    CHECK_THROWS_AS(run(), CLI::ValidationError);

    args = {"--string", "val_with_opt1", "--opt1"};
    run();

    args = {"--opt1", "--string", "val_with_opt1"};  // order is not revelant
    run();
}

The check metho…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by wsbak
Comment options

You must be logged in to vote
1 reply
@phlptp
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants