2022-04-08 07:52:16 +00:00
# pragma once
2024-05-27 11:44:45 +00:00
# include <unordered_map>
# include <vector>
2024-07-25 14:44:17 +00:00
# include <Client/LineReader.h>
2022-04-08 07:52:16 +00:00
# include <Loggers/Loggers.h>
2024-05-27 11:44:45 +00:00
# include "DisksClient.h"
# include "ICommand_fwd.h"
2022-04-08 07:52:16 +00:00
# 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>
2022-12-08 17:20:54 +00:00
# include <Poco/Util/Application.h>
2022-04-08 07:52:16 +00:00
namespace DB
{
2022-12-08 17:20:54 +00:00
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
2022-04-08 07:52:16 +00:00
{
public :
2024-05-27 11:44:45 +00:00
void addOptions ( ) ;
2022-04-08 07:52:16 +00:00
2024-05-27 11:44:45 +00:00
void processOptions ( ) ;
2022-04-08 07:52:16 +00:00
2024-05-31 13:10:42 +00:00
bool processQueryText ( const String & text ) ;
2022-04-08 07:52:16 +00:00
2024-05-27 11:44:45 +00:00
void init ( const std : : vector < String > & common_arguments ) ;
2022-04-08 07:52:16 +00:00
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 ( ) ;
2022-04-08 07:52:16 +00:00
2024-05-27 11:44:45 +00:00
static void parseAndCheckOptions (
const std : : vector < String > & arguments , const ProgramOptionsDescription & options_description , CommandLineOptions & options ) ;
2022-04-08 07:52:16 +00:00
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 ;
2022-04-08 07:52:16 +00:00
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 ( ) ;
2022-04-08 07:52:16 +00:00
2024-05-27 11:44:45 +00:00
String getDefaultConfigFileName ( ) ;
2022-04-08 07:52:16 +00:00
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 ;
2024-10-24 10:48:40 +00:00
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.
2024-05-27 11:44:45 +00:00
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 ;
2022-04-08 07:52:16 +00:00
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 ;
2022-04-08 07:52:16 +00:00
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 { } ;
2022-04-08 07:52:16 +00:00
} ;
}