ClickHouse/programs/keeper-client/KeeperClient.h

75 lines
1.9 KiB
C++
Raw Normal View History

2023-03-10 02:23:57 +00:00
#pragma once
#include "Parser.h"
#include "Commands.h"
2023-03-10 02:23:57 +00:00
#include <Common/ZooKeeper/ZooKeeper.h>
#include <Client/LineReader.h>
#include <IO/ReadBufferFromPocoSocket.h>
#include <IO/WriteBufferFromPocoSocket.h>
#include <Parsers/ASTLiteral.h>
#include <Poco/Net/StreamSocket.h>
2023-03-10 02:23:57 +00:00
#include <Poco/Util/Application.h>
#include <filesystem>
2023-04-27 00:11:45 +00:00
namespace fs = std::filesystem;
2023-03-10 02:23:57 +00:00
namespace DB
{
static const NameSet four_letter_word_commands
{
"ruok", "mntr", "srvr", "stat", "srst", "conf",
"cons", "crst", "envi", "dirs", "isro", "wchs",
"wchc", "wchp", "dump", "csnp", "lgif", "rqld",
};
2023-03-10 02:23:57 +00:00
class KeeperClient: public Poco::Util::Application
{
public:
KeeperClient() = default;
void initialize(Poco::Util::Application & self) override;
int main(const std::vector<String> & args) override;
void defineOptions(Poco::Util::OptionSet & options) override;
2023-04-27 00:11:45 +00:00
fs::path getAbsolutePath(const String & relative) const;
void askConfirmation(const String & prompt, std::function<void()> && callback);
String executeFourLetterCommand(const String & command);
zkutil::ZooKeeperPtr zookeeper;
std::filesystem::path cwd = "/";
std::function<void()> confirmation_callback;
inline static std::map<String, Command> commands;
2023-03-10 02:23:57 +00:00
protected:
void runInteractive();
void runInteractiveReplxx();
void runInteractiveInputStream();
2023-03-10 02:23:57 +00:00
bool processQueryText(const String & text);
void loadCommands(std::vector<Command> && new_commands);
2023-03-10 02:23:57 +00:00
2023-04-27 00:11:45 +00:00
std::vector<String> getCompletions(const String & prefix) const;
2023-03-10 02:23:57 +00:00
String history_file;
UInt32 history_max_entries; /// Maximum number of entries in the history file.
2023-03-10 02:23:57 +00:00
LineReader::Suggest suggest;
zkutil::ZooKeeperArgs zk_args;
bool ask_confirmation = true;
bool waiting_confirmation = false;
2023-04-27 00:11:45 +00:00
std::vector<String> registered_commands_and_four_letter_words;
2023-03-10 02:23:57 +00:00
};
}