| 56 | |
| 57 | |
| 58 | int main(int argc, char ** argv) |
| 59 | { |
| 60 | try |
| 61 | { |
| 62 | if (argc != 2) |
| 63 | { |
| 64 | std::cerr << "usage: " << argv[0] << " hosts" << std::endl; |
| 65 | return 2; |
| 66 | } |
| 67 | |
| 68 | Poco::AutoPtr<Poco::ConsoleChannel> channel = new Poco::ConsoleChannel(std::cerr); |
| 69 | Poco::Logger::root().setChannel(channel); |
| 70 | Poco::Logger::root().setLevel("trace"); |
| 71 | |
| 72 | zkutil::ZooKeeper zk(argv[1]); |
| 73 | LineReader lr({}, false, {"\\"}, {}); |
| 74 | |
| 75 | do |
| 76 | { |
| 77 | const auto & line = lr.readLine(":3 ", ":3 "); |
| 78 | if (line.empty()) |
| 79 | break; |
| 80 | |
| 81 | try |
| 82 | { |
| 83 | std::stringstream ss(line); // STYLE_CHECK_ALLOW_STD_STRING_STREAM |
| 84 | |
| 85 | std::string cmd; |
| 86 | ss >> cmd; |
| 87 | |
| 88 | if (cmd == "q" || cmd == "quit" || cmd == "exit" || cmd == ":q") |
| 89 | break; |
| 90 | |
| 91 | std::string path; |
| 92 | ss >> path; |
| 93 | if (cmd == "ls") |
| 94 | { |
| 95 | std::string w; |
| 96 | ss >> w; |
| 97 | bool watch = w == "w"; |
| 98 | zkutil::EventPtr event = watch ? std::make_shared<Poco::Event>() : nullptr; |
| 99 | std::vector<std::string> v = zk.getChildren(path, nullptr, event); |
| 100 | for (const auto & child : v) |
| 101 | std::cout << child << std::endl; |
| 102 | if (watch) |
| 103 | waitForWatch(event); |
| 104 | } |
| 105 | else if (cmd == "create") |
| 106 | { |
| 107 | DB::ReadBufferFromString in(line); |
| 108 | |
| 109 | std::string path_ignored; |
| 110 | std::string data; |
| 111 | std::string mode; |
| 112 | |
| 113 | DB::assertString("create", in); |
| 114 | DB::skipWhitespaceIfAny(in); |
| 115 | readMaybeQuoted(path_ignored, in); |
nothing calls this directly
no test coverage detected