filmstro_optionsparser
|
This class provides a parser for command line arguments in unix style.
You can add options with long arguments prefixed by "--" or short arguments using "-". It will create a help text and error messages automatically. An example would look like that:
OptionsParser options; options.header = "My console application"; options.footer = "Build date: " + String(__DATE__) + " at " + String(__TIME__); OptionsParser::Option* option = options.addOption ("help", "h", OptionsParser::OptBoolean); option->longArg = "help"; option->helpText = "Display this help text and exit"; option = options.addOption ("logfile", "l", OptionsParser::OptFile, false); option->longArg = "logfile"; option->helpText = "Set a logfile to enable logging"; if (! options.parseArguments (StringArray::fromTokens (commandLine, true))) { std::cout << options.getErrorMessage () << std::endl; exit (-1); } if (options.getErrorMessage().isNotEmpty()) // there can also be warnings... std::cout << options.getErrorMessage () << std::endl; if (options.getOptBoolean("help")) { std::cout << options.getHelpText() << std::endl; exit (0); } if (options.isOptionSet ("logfile")) { File logfile = options.getOptFile("logfile"); Logger::setCurrentLogger (new FileLogger (logfile, "Started My Application")); }
It will understand the following types:
For an option you can set following options
Brighton, 2017