Skip to content

Support for default int/float/string values? #58

@sdaau

Description

@sdaau

Thanks for a great library!

I was just wondering, how could I implement default values easily?

That is, if --myoption argument is not specified on the command line, then, say, the corresponding float myoption in C code gets the value (for example) 5.0 ...

I have seen in the code https://github.com/cofyc/argparse/blob/master/argparse.h, the last three arguments to the macros are:

 *  `callback`:
 *    function is called when corresponding argument is parsed.
 *
 *  `data`:
 *    associated data. Callbacks can use it like they want.
 *
 *  `flags`:
 *    option flags.

So, I guess, I'd have to implement a custom callback for all such options, and then assign data in the callback, in case the command line argument was not found on the command line. But then, I'm not sure how could I check in the callback, whether the command line argument was present or not?

Is there an example that shows such usage (with default values for arguments, if they are not set on the command line)?

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