2022-12-08 17:54:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
#include <Disks/IDisk.h>
|
2023-11-30 03:09:55 +00:00
|
|
|
#include <Disks/DiskSelector.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
|
|
|
|
|
|
|
#include <Common/Config/ConfigProcessor.h>
|
2022-12-08 17:20:54 +00:00
|
|
|
#include <Poco/Util/Application.h>
|
2022-06-06 11:14:50 +00:00
|
|
|
|
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;
|
2022-06-16 17:38:33 +00:00
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
virtual ~ICommand() = default;
|
2022-06-16 17:38:33 +00:00
|
|
|
|
|
|
|
virtual void execute(
|
2022-04-08 07:52:16 +00:00
|
|
|
const std::vector<String> & command_arguments,
|
2023-11-30 03:09:55 +00:00
|
|
|
std::shared_ptr<DiskSelector> & disk_selector,
|
2022-06-16 17:38:33 +00:00
|
|
|
Poco::Util::LayeredConfiguration & config) = 0;
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2022-06-21 14:40:22 +00:00
|
|
|
const std::optional<ProgramOptionsDescription> & getCommandOptions() const { return command_option_description; }
|
|
|
|
|
|
|
|
void addOptions(ProgramOptionsDescription & options_description);
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2022-06-16 17:38:33 +00:00
|
|
|
virtual void processOptions(Poco::Util::LayeredConfiguration & config, po::variables_map & options) const = 0;
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2022-06-21 14:40:22 +00:00
|
|
|
protected:
|
2022-04-08 07:52:16 +00:00
|
|
|
void printHelpMessage() const;
|
|
|
|
|
2022-12-08 17:20:54 +00:00
|
|
|
static String validatePathAndGetAsRelative(const String & path);
|
2022-04-08 07:52:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
String command_name;
|
|
|
|
String description;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::optional<ProgramOptionsDescription> command_option_description;
|
|
|
|
String usage;
|
|
|
|
po::positional_options_description positional_options_description;
|
|
|
|
};
|
|
|
|
|
2022-12-08 17:20:54 +00:00
|
|
|
using CommandPtr = std::unique_ptr<ICommand>;
|
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 17:53:05 +00:00
|
|
|
DB::CommandPtr makeCommandCopy();
|
|
|
|
DB::CommandPtr makeCommandLink();
|
|
|
|
DB::CommandPtr makeCommandList();
|
|
|
|
DB::CommandPtr makeCommandListDisks();
|
|
|
|
DB::CommandPtr makeCommandMove();
|
|
|
|
DB::CommandPtr makeCommandRead();
|
|
|
|
DB::CommandPtr makeCommandRemove();
|
|
|
|
DB::CommandPtr makeCommandWrite();
|
|
|
|
DB::CommandPtr makeCommandMkDir();
|