#pragma once #include #include #include #include #include "DisksClient.h" #include "ICommand_fwd.h" #include #include #include #include namespace DB { using ProgramOptionsDescription = boost::program_options::options_description; using CommandLineOptions = boost::program_options::variables_map; class DisksApp : public Poco::Util::Application { public: void addOptions(); void processOptions(); bool processQueryText(const String & text); void init(const std::vector & common_arguments); int main(const std::vector & /*args*/) override; CommandPtr getCommandByName(const String & command) const; void initializeHistoryFile(); static void parseAndCheckOptions( const std::vector & arguments, const ProgramOptionsDescription & options_description, CommandLineOptions & options); void printEntryHelpMessage() const; void printAvailableCommandsHelpMessage() const; void printCommandHelpMessage(String command_name) const; void printCommandHelpMessage(CommandPtr command) const; String getCommandLineWithAliases(CommandPtr command) const; std::vector getCompletions(const String & prefix) const; std::vector getEmptyCompletion(String command_name) const; ~DisksApp() override; private: void runInteractive(); void runInteractiveReplxx(); void runInteractiveTestMode(); String getDefaultConfigFileName(); std::vector getCommandsToComplete(const String & command_prefix) const; // Fields responsible for the REPL work String history_file; UInt32 history_max_entries = 0; /// Maximum number of entries in the history file. Needs to be initialized to 0 since we don't have a proper constructor. Worry not, actual value is set within the initializeHistoryFile method. LineReader::Suggest suggest; static LineReader::Patterns query_extenders; static LineReader::Patterns query_delimiters; static String word_break_characters; // General command line arguments parsing fields SharedContextHolder shared_context; ContextMutablePtr global_context; ProgramOptionsDescription options_description; CommandLineOptions options; std::unordered_map command_descriptions; std::optional query; const std::unordered_map aliases = {{"cp", "copy"}, {"mv", "move"}, {"ls", "list"}, {"list_disks", "list-disks"}, {"ln", "link"}, {"rm", "remove"}, {"cat", "read"}, {"r", "read"}, {"w", "write"}, {"create", "touch"}, {"delete", "remove"}, {"ls-disks", "list-disks"}, {"ls_disks", "list-disks"}, {"packed_io", "packed-io"}, {"change-dir", "cd"}, {"change_dir", "cd"}, {"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"}}; std::set multidisk_commands = {"copy", "packed-io", "switch-disk", "cd"}; std::unique_ptr client{}; }; }