ClickHouse/programs/disks/DisksApp.h

108 lines
3.2 KiB
C++
Raw Normal View History

#pragma once
2024-05-27 11:44:45 +00:00
#include <unordered_map>
#include <vector>
#include <Client/ReplxxLineReader.h>
#include <Loggers/Loggers.h>
2024-05-27 11:44:45 +00:00
#include "DisksClient.h"
#include "ICommand_fwd.h"
#include <Interpreters/Context.h>
2024-05-27 11:44:45 +00:00
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <Poco/Util/Application.h>
namespace DB
{
using ProgramOptionsDescription = boost::program_options::options_description;
using CommandLineOptions = boost::program_options::variables_map;
2024-05-27 11:44:45 +00:00
class DisksApp : public Poco::Util::Application
{
public:
2024-05-27 11:44:45 +00:00
void addOptions();
2024-05-27 11:44:45 +00:00
void processOptions();
2024-05-31 13:10:42 +00:00
bool processQueryText(const String & text);
2024-05-27 11:44:45 +00:00
void init(const std::vector<String> & common_arguments);
2024-05-27 11:44:45 +00:00
int main(const std::vector<String> & /*args*/) override;
2024-05-31 13:10:42 +00:00
CommandPtr getCommandByName(const String & command) const;
2024-05-27 11:44:45 +00:00
void initializeHistoryFile();
2024-05-27 11:44:45 +00:00
static void parseAndCheckOptions(
const std::vector<String> & arguments, const ProgramOptionsDescription & options_description, CommandLineOptions & options);
2024-06-10 16:17:36 +00:00
void printEntryHelpMessage() const;
void printAvailableCommandsHelpMessage() const;
void printCommandHelpMessage(String command_name) const;
void printCommandHelpMessage(CommandPtr command) const;
String getCommandLineWithAliases(CommandPtr command) const;
2024-05-27 11:44:45 +00:00
std::vector<String> getCompletions(const String & prefix) const;
2024-06-10 16:17:36 +00:00
std::vector<String> getEmptyCompletion(String command_name) const;
2024-05-27 11:44:45 +00:00
~DisksApp() override;
private:
2024-06-13 19:14:16 +00:00
void runInteractive();
2024-05-27 11:44:45 +00:00
void runInteractiveReplxx();
2024-06-13 19:14:16 +00:00
void runInteractiveTestMode();
2024-05-27 11:44:45 +00:00
String getDefaultConfigFileName();
2024-06-10 16:17:36 +00:00
std::vector<String> getCommandsToComplete(const String & command_prefix) const;
2024-05-27 11:44:45 +00:00
// Fields responsible for the REPL work
String history_file;
LineReader::Suggest suggest;
2024-05-31 13:10:42 +00:00
static LineReader::Patterns query_extenders;
static LineReader::Patterns query_delimiters;
static String word_break_characters;
2024-05-31 13:10:42 +00:00
// General command line arguments parsing fields
2024-06-17 17:40:52 +00:00
SharedContextHolder shared_context;
2024-05-27 11:44:45 +00:00
ContextMutablePtr global_context;
ProgramOptionsDescription options_description;
CommandLineOptions options;
std::unordered_map<String, CommandPtr> command_descriptions;
2024-05-29 14:59:50 +00:00
std::optional<String> query;
2024-05-27 11:44:45 +00:00
const std::unordered_map<String, String> aliases
= {{"cp", "copy"},
{"mv", "move"},
{"ls", "list"},
{"list_disks", "list-disks"},
{"ln", "link"},
{"rm", "remove"},
2024-06-26 15:59:15 +00:00
{"cat", "read"},
2024-05-27 11:44:45 +00:00
{"r", "read"},
{"w", "write"},
2024-06-26 15:59:15 +00:00
{"create", "touch"},
2024-05-27 11:44:45 +00:00
{"delete", "remove"},
{"ls-disks", "list-disks"},
{"ls_disks", "list-disks"},
2024-06-10 16:17:36 +00:00
{"packed_io", "packed-io"},
{"change-dir", "cd"},
{"change_dir", "cd"},
2024-06-13 19:14:16 +00:00
{"switch_disk", "switch-disk"},
{"current", "current_disk_with_path"},
{"current_disk", "current_disk_with_path"},
{"current_path", "current_disk_with_path"},
{"cur", "current_disk_with_path"}};
2024-05-27 11:44:45 +00:00
std::set<String> multidisk_commands = {"copy", "packed-io", "switch-disk", "cd"};
std::unique_ptr<DisksClient> client{};
};
}