-
Notifications
You must be signed in to change notification settings - Fork 82
Module: Argument Parser
Hannes Hauswedell edited this page Mar 6, 2017
·
19 revisions
Links:
- Boost: http://www.boost.org/doc/libs/1_58_0/doc/html/program_options.html
- follow POSIX guidelines: http://bioportal.weizmann.ac.il/course/prog2/tutorial/essential/attributes/_posix.html
- a modern c++ standalone arg-parser: https://github.com/adishavit/argh
Possible interface:
addOption(char const shortID, // -o
std::string const & longID, // --output
TValue & savePlace, // myOptions.outputFile (std::string)
std::function<bool(TValue const&)> && validator = [] (TValue const&) { return true; } );
savePlace
would be an existing variable that also defines the type of the argument. savePlace
can be set to a default value upon definition/creation / outside of the addArgument function.
validator
is a callable that verifies the argument. It can be user-specified, but there shall be pre-defined validators for integral ranges (takes a pair of integral) or file extensions (takes a container of std::string).
Wishlist from h-2:
- also support enums as TValue and offer a validator that accepts the enum labels as valid strings. This will be a little tricky to implement, but one could check how e.g. Cereal get string values from enum labels.
- the
input_file_validator
(and output_file_validator and directory...) shall check via http://en.cppreference.com/w/cpp/filesystem that the file/directory exists / is readable / writeable et cetera.