2022-04-08 07:52:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Disks/IDisk.h>
|
2022-06-06 11:14:50 +00:00
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
#include <Poco/Util/Application.h>
|
2022-06-06 11:14:50 +00:00
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
#include <IO/WriteBufferFromFileDescriptor.h>
|
|
|
|
#include <IO/ReadBufferFromFileDescriptor.h>
|
|
|
|
#include <IO/copyData.h>
|
2022-06-06 11:14:50 +00:00
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
#include <boost/program_options.hpp>
|
2022-06-06 11:14:50 +00:00
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
#include <Common/TerminalSize.h>
|
2022-06-06 11:14:50 +00:00
|
|
|
#include <Common/Config/ConfigProcessor.h>
|
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
using ProgramOptionsDescription = boost::program_options::options_description;
|
|
|
|
using CommandLineOptions = boost::program_options::variables_map;
|
|
|
|
|
|
|
|
class ICommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ICommand() = default;
|
|
|
|
virtual ~ICommand() = default;
|
|
|
|
void execute(
|
|
|
|
const std::vector<String> & command_arguments,
|
2022-06-06 11:56:57 +00:00
|
|
|
DB::ContextMutablePtr & global_context,
|
2022-06-06 11:14:50 +00:00
|
|
|
Poco::Util::LayeredConfiguration & config);
|
2022-04-08 07:52:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void processOptions(
|
2022-06-06 11:14:50 +00:00
|
|
|
Poco::Util::LayeredConfiguration & config,
|
2022-04-08 07:52:16 +00:00
|
|
|
po::variables_map & options) const = 0;
|
|
|
|
|
|
|
|
virtual void executeImpl(
|
|
|
|
const DB::ContextMutablePtr & global_context,
|
2022-06-06 11:14:50 +00:00
|
|
|
const Poco::Util::LayeredConfiguration & config) const = 0;
|
2022-04-08 07:52:16 +00:00
|
|
|
|
|
|
|
void printHelpMessage() const;
|
|
|
|
|
|
|
|
static String fullPathWithValidate(const DiskPtr & disk, const String & path);
|
|
|
|
|
|
|
|
public:
|
|
|
|
String command_name;
|
|
|
|
String description;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::optional<ProgramOptionsDescription> command_option_description;
|
|
|
|
String usage;
|
|
|
|
po::positional_options_description positional_options_description;
|
|
|
|
std::vector<String> pos_arguments;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandCopy();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandLink();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandList();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandListDisks();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandMove();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandRead();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandRemove();
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandWrite();
|