30 auto command_map = create_command_map();
32 bpo::options_description vis_desc(
"Options");
33 auto vis_opts = vis_desc.add_options();
34 vis_opts(
"help,h",
"show usage help message");
36 bpo::options_description hidden_desc;
37 auto hidden_opts = hidden_desc.add_options();
38 hidden_opts(
"subargs", bpo::value<std::vector<std::string>>(),
"args");
40 bpo::positional_options_description pos_desc;
41 pos_desc.add(
"subargs", -1);
43 bpo::options_description cmdline_options;
44 cmdline_options.add(vis_desc).add(hidden_desc);
46 bpo::variables_map vm;
47 auto parsed_args = bpo::command_line_parser(argc,
argv).options(cmdline_options).positional(pos_desc).allow_unregistered().run();
48 bpo::store(parsed_args, vm);
50 std::vector<std::string> args = bpo::collect_unrecognized(parsed_args.options, bpo::include_positional);
52 auto show_help = [&](std::ostream&
os) {
54 "Usage: trace_api_util <options> command ...\n"
58 for (
const auto& e: command_map) {
59 os <<
" " << e.second->name <<
" " << e.second->slug <<
"\n";
62 os <<
"\n" << vis_desc <<
"\n";
65 if (args.size() < 1) {
66 if (vm.count(
"help") > 0) {
71 std::cerr <<
"Error: No command provided\n\n";
74 }
else if (command_map.count(args.at(0)) == 0) {
75 std::cerr <<
"Error: unknown command \"" << args.at(0) <<
"\"\n\n";
81 return command_map.at(args.at(0))->func(vm, std::vector<std::string>(args.begin() + 1, args.end()));