int Kernel::do_switches() { try { // add -h, -v, etc addBasicSwitchSet(); // add the options for the derived application addSwitches(); // parse the command line parseSwitches(); } catch (std::exception const& e) { const std::string s("Caught exception handling switches: "); printError(s + e.what()); return 1; } catch (...) { printError("Caught unknown exception handling switches"); return 1; } return 0; }
void Kernel::doSwitches(int argc, const char *argv[], ProgramArgs& args) { StringList stringArgs; OptionsMap& stageOptions = m_manager.stageOptions(); // Scan the argument vector for extra stage options. Pull them out and // stick them in the list. Let the ProgramArgs handle everything else. // NOTE: This depends on the format being "option=value" rather than // "option value". This is what we've always expected, so no problem, // but it would be better to be more flexible. for (int i = 0; i < argc; ++i) { std::string stageName, opName, value; if (parseOption(argv[i], stageName, opName, value)) { Option op(opName, value); stageOptions[stageName].add(op); } else stringArgs.push_back(argv[i]); } try { addBasicSwitches(args); // parseSimple allows us to scan for the help option without // raising exception about missing arguments and so on. args.parseSimple(stringArgs); addSwitches(args); if (!m_showHelp) { args.reset(); args.parse(stringArgs); } } catch (arg_error& e) { throw pdal_error(e.m_error); } }