ClickHouse/programs/keeper-client/KeeperClient.h

70 lines
1.7 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();
bool processQueryText(const String & text);
2023-03-14 19:32:48 +00:00
void executeQuery(const String & query);
2023-03-10 02:23:57 +00:00
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;
LineReader::Suggest suggest;
zkutil::ZooKeeperArgs zk_args;
bool need_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
};
}