Skip to content

Know if argument was used without repeating option string #428

Description

@RL-S

Currently, the README says to use ArgumentParser::is_used(std::string_view) to check if an argument was used. This returns Argument::m_is_used.

I don't want to repeat a string. That's error-prone and can't be caught by the compiler if anything changes. I'd prefer the following pattern:

argparse::Argument& testArg = program.add_argument("-t", "--test").flag();
program.parse_args(argc, argv);
if ( testArg.is_used() ){
    ;/* do something */
}

and maybe let operator bool() redirect to that function, too:

if (testArg){/*.../*}

Is this intentionally disallowed? Would you be willing to accept a merge request to add this feature?

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