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-06-14 11:06:56 +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);
|
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;
|
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());
|
|
|
|
}
|
2024-05-30 14:07:25 +00:00
|
|
|
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());
|
2024-09-19 11:51:02 +00:00
|
|
|
|
|
|
|
return client.getCurrentDiskWithPath();
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|