2022-04-08 07:52:16 +00:00
|
|
|
#include "ICommand.h"
|
2024-05-27 11:44:45 +00:00
|
|
|
#include "DisksClient.h"
|
2023-08-09 00:19:02 +00:00
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2024-05-27 11:44:45 +00:00
|
|
|
extern const int BAD_ARGUMENTS;
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
CommandLineOptions ICommand::processCommandLineArguments(const Strings & commands)
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
2024-05-27 11:44:45 +00:00
|
|
|
CommandLineOptions options;
|
|
|
|
auto parser = po::command_line_parser(commands);
|
|
|
|
parser.options(options_description).positional(positional_options_description).allow_unregistered();
|
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;
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
return 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)
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
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());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return client.getCurrentDiskWithPath();
|
|
|
|
}
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|