mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 19:02:04 +00:00
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include "ICommand.h"
|
|
#include "DisksClient.h"
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int BAD_ARGUMENTS;
|
|
}
|
|
|
|
CommandLineOptions ICommand::processCommandLineArguments(const Strings & commands)
|
|
{
|
|
CommandLineOptions options;
|
|
auto parser = po::command_line_parser(commands);
|
|
parser.options(options_description).positional(positional_options_description);
|
|
|
|
po::parsed_options parsed = parser.run();
|
|
po::store(parsed, options);
|
|
|
|
return options;
|
|
}
|
|
|
|
void ICommand::execute(const Strings & commands, DisksClient & client)
|
|
{
|
|
try
|
|
{
|
|
processCommandLineArguments(commands);
|
|
}
|
|
catch (std::exception & exc)
|
|
{
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "{}", exc.what());
|
|
}
|
|
executeImpl(processCommandLineArguments(commands), client);
|
|
}
|
|
|
|
DiskWithPath & ICommand::getDiskWithPath(DisksClient & client, const CommandLineOptions & options, const String & name)
|
|
{
|
|
auto disk_name = getValueFromCommandLineOptionsWithOptional<String>(options, name);
|
|
if (disk_name.has_value())
|
|
{
|
|
return client.getDiskWithPath(disk_name.value());
|
|
}
|
|
else
|
|
{
|
|
return client.getCurrentDiskWithPath();
|
|
}
|
|
}
|
|
|
|
}
|