MCPcopy Create free account
hub / github.com/ByConity/ByConity / mainEntryStorageTools

Function mainEntryStorageTools

programs/storage-tools/StorageTools.cpp:27–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace po = boost::program_options;
26
27int mainEntryStorageTools(int argc, char** argv) {
28 try {
29 po::options_description desc("storage tools");
30
31 desc.add_options()
32 ("log_level", po::value<String>()->default_value("information"), "logging level of storage tools")
33 ("command", po::value<String>(), "command to use, supported are inspect_part/help")
34 ("args", po::value<std::vector<String>>(), "command arguments");
35
36 po::positional_options_description pos_desc;
37 pos_desc.add("command", 1).add("args", -1);
38
39 po::variables_map vm;
40 po::parsed_options parsed_opts = po::command_line_parser(argc, argv)
41 .options(desc)
42 .positional(pos_desc)
43 .allow_unregistered()
44 .run();
45
46 po::store(parsed_opts, vm);
47 po::notify(vm);
48
49 Poco::AutoPtr<Poco::PatternFormatter> formatter(new Poco::PatternFormatter("%Y.%m.%d %H:%M:%S.%F <%p> %s: %t"));
50 Poco::AutoPtr<Poco::ConsoleChannel> console_chanel(new Poco::ConsoleChannel);
51 Poco::AutoPtr<Poco::FormattingChannel> channel(new Poco::FormattingChannel(formatter, console_chanel));
52 Poco::Logger::root().setLevel(vm["log_level"].as<String>());
53 Poco::Logger::root().setChannel(channel);
54
55 if (!vm.count("command")) {
56 std::cerr << "Missing required field command\n" << desc << std::endl;
57 return 1;
58 }
59
60 String command = vm["command"].as<String>();
61
62 if (command == "help") {
63 std:: cout << desc << std::endl;
64 } else if (command == "inspect_part") {
65 std::vector<std::string> opts = po::collect_unrecognized(parsed_opts.options, po::include_positional);
66 opts.erase(opts.begin());
67 return parseAndRunInspectPartTask(opts);
68 // } else if (command == "check_s3") {
69 // std::vector<std::string> opts = po::collect_unrecognized(parsed_opts.options, po::include_positional);
70 // opts.erase(opts.begin());
71 // return parseAndRunS3CheckTask(opts);
72 } else {
73 std::cerr << "Unknown command " << command << ", options are:\n"
74 << desc << std::endl;
75 }
76 } catch (...) {
77 std::cerr << getCurrentExceptionMessage(true) << std::endl;
78 return 1;
79 }
80
81 return 0;
82}

Callers 1

mainFunction · 0.85

Calls 10

storeFunction · 0.85
setChannelMethod · 0.80
addMethod · 0.45
runMethod · 0.45
setLevelMethod · 0.45
countMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected