static int read_commandline(options& opt, std::vector<std::string>& args) { boost::program_options::options_description o_general("Options"); o_general.add_options() ("help,h", "display this message") ("api,a", boost::program_options::value(&opt.api_host), "api host (default: api.supermarx.nl)") ("config,C", boost::program_options::value(&opt.config), "path to the configfile (default: ./config.yaml)"); boost::program_options::variables_map vm; boost::program_options::options_description options("Allowed options"); options.add(o_general); boost::program_options::parsed_options parsed(boost::program_options::command_line_parser(args).options(options).allow_unregistered().run()); boost::program_options::store(parsed, vm); args = boost::program_options::collect_unrecognized(parsed.options, boost::program_options::include_positional); try { boost::program_options::notify(vm); } catch(const boost::program_options::required_option &e) { std::cerr << "You forgot this: " << e.what() << std::endl; return EXIT_FAILURE; } if(vm.count("help")) { std::cout << "SuperMarx commandline interface Paul. [https://github.com/SuperMarx/paul]" << std::endl << "Usage [1]: ./paul [options] <empty>" << std::endl << " Drops Paul into an interactive shell." << std::endl << "Usage [2]: ./paul [options] action" << std::endl << std::endl << "Actions:" << std::endl << " login logs an user in" << std::endl << " quit drops from the interactive cell (if applicable)" << std::endl << std::endl << o_general; return EXIT_FAILURE; } if(!vm.count("api")) opt.api_host = "https://api.supermarx.nl"; if(!vm.count("config")) opt.config = "./config.yaml"; return EXIT_SUCCESS; }
static int main(int argc, char** argv) { std::string action, model_file, trace_file; boost::program_options::options_description o_general("General options"); o_general.add_options() ("help,h", "display this message"); boost::program_options::options_description o_hidden("Hidden options"); o_hidden.add_options() ("action", boost::program_options::value<decltype(trace_file)>(&action), "either xtr or hr") ("trace", boost::program_options::value<decltype(trace_file)>(&trace_file), "path to trace file in xtr") ("model", boost::program_options::value<decltype(model_file)>(&model_file), "path to model file in intermediate format"); boost::program_options::variables_map vm; boost::program_options::positional_options_description pos; pos.add("action", 1); pos.add("trace", 1); pos.add("model", 1); boost::program_options::options_description options("Allowed options"); options.add(o_general).add(o_hidden); try { boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(options).positional(pos).run(), vm); } catch(boost::program_options::unknown_option &e) { std::cerr << "Unknown option --" << e.get_option_name() << ", see --help" << std::endl; return -1; } if(vm.count("help")) { std::cout << "Program for converting UPPAAL traces to Octopus traces. [https://github.com/Wassasin/uppaal2octopus]" << std::endl << "Usage: ./uppaal2octopus [options] xtr <model> <trace>" << std::endl << " ./uppaal2octopus [options] hr <trace>" << std::endl << std::endl << o_general; return 0; } try { boost::program_options::notify(vm); } catch(const boost::program_options::required_option &e) { std::cerr << "You forgot this: " << e.what() << std::endl; return -1; } converter c([&](const octopus::event_t& e) { std::cout << e << std::endl; }); auto f = [&](const location_t loc, const clock_t clock, const startend_e startEnd) { c.add(loc, clock, startEnd); }; if(action == "xtr") { if(model_file == "" || trace_file == "") { std::cerr << "Please specify both a model and a trace, see --help" << std::endl; return -1; } std::cerr << "Model: " << model_file << std::endl << "Trace: " << trace_file << std::endl; xtrparser p; p.parse(model_file, trace_file, f); c.flush(); } else if(action == "hr") { if(trace_file == "") { std::cerr << "Please specify a trace generated by verifyta, see --help" << std::endl; return -1; } std::cerr << "Trace: " << trace_file << std::endl; hrparser::parse(trace_file, f); c.flush(); } else if(action == "") std::cerr << "Specify an action, see --help" << std::endl; else std::cerr << "Unknown action '" << action << "', see --help" << std::endl; return 1; }