ClickHouse/programs/disks/ICommand.cpp

48 lines
1.1 KiB
C++
Raw Permalink Normal View History

#include "ICommand.h"
2024-05-27 11:44:45 +00:00
#include "DisksClient.h"
2023-08-09 00:19:02 +00:00
namespace DB
{
namespace ErrorCodes
{
2024-06-14 11:06:56 +00:00
extern const int BAD_ARGUMENTS;
}
2024-05-27 11:44:45 +00:00
CommandLineOptions ICommand::processCommandLineArguments(const Strings & commands)
{
2024-05-27 11:44:45 +00:00
CommandLineOptions options;
auto parser = po::command_line_parser(commands);
2024-06-26 17:25:43 +00:00
parser.options(options_description).positional(positional_options_description);
2022-06-16 17:38:33 +00:00
2024-05-27 11:44:45 +00:00
po::parsed_options parsed = parser.run();
po::store(parsed, options);
return options;
}
2024-05-27 11:44:45 +00:00
void ICommand::execute(const Strings & commands, DisksClient & client)
2022-06-21 14:40:22 +00:00
{
2024-05-27 11:44:45 +00:00
try
{
processCommandLineArguments(commands);
}
catch (std::exception & exc)
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "{}", exc.what());
}
executeImpl(processCommandLineArguments(commands), client);
2022-06-21 14:40:22 +00:00
}
2024-05-27 11:44:45 +00:00
DiskWithPath & ICommand::getDiskWithPath(DisksClient & client, const CommandLineOptions & options, const String & name)
{
2024-05-27 11:44:45 +00:00
auto disk_name = getValueFromCommandLineOptionsWithOptional<String>(options, name);
if (disk_name.has_value())
return client.getDiskWithPath(disk_name.value());
2024-09-19 11:51:02 +00:00
return client.getCurrentDiskWithPath();
}
}