Skip to content

Validating an option using a different option's value #720

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

You must be logged in to vote
MyApp::MyApp() : CLI::App("Description", "Appname")
{

client_cnt = 100;
clientidx_start = 0;

add_option("--client-cnt", client_cnt)->check(CLI::Range(1, 10000))->trigger_on_parse();
add_option("--clientidx-start", clientidx_start)->check(CLI::PositiveNumber & CLI::Validator([&](const std::string &checkString) {
        std::uint32_t val{0};
        details::lexical_cast(checkString, val);
        if ((client_cnt + val) > 10000) {
            return "The number of clients exceeds the maximum client index of 10000";
        }
        return "";
    }));
}

I think this will work(haven't checked exactly).
Two things, --client-cnt would have the trigger_on_parse() modifier set, this means th…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by dmf254
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