2022-04-08 07:52:16 +00:00
|
|
|
#include "ICommand.h"
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ICommand::printHelpMessage() const
|
|
|
|
{
|
2022-06-16 17:38:33 +00:00
|
|
|
std::cout << "Command: " << command_name << '\n';
|
|
|
|
std::cout << "Description: " << description << '\n';
|
|
|
|
std::cout << "Usage: " << usage << '\n';
|
|
|
|
|
|
|
|
if (command_option_description)
|
|
|
|
{
|
|
|
|
auto options = *command_option_description;
|
|
|
|
if (!options.options().empty())
|
|
|
|
std::cout << options << '\n';
|
|
|
|
}
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 14:40:22 +00:00
|
|
|
void ICommand::addOptions(ProgramOptionsDescription & options_description)
|
|
|
|
{
|
|
|
|
if (!command_option_description || command_option_description->options().empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
options_description.add(*command_option_description);
|
|
|
|
}
|
|
|
|
|
2022-04-08 07:52:16 +00:00
|
|
|
String ICommand::fullPathWithValidate(const DiskPtr & disk, const String & path)
|
|
|
|
{
|
2022-06-21 14:40:22 +00:00
|
|
|
if (fs::path(path).lexically_normal().string() != path)
|
|
|
|
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Path {} is not normalized", path);
|
|
|
|
|
|
|
|
String disk_path = fs::canonical(fs::path(disk->getPath())) / "";
|
|
|
|
String full_path = (fs::absolute(disk_path) / path).lexically_normal();
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2022-06-16 17:38:33 +00:00
|
|
|
if (!full_path.starts_with(disk_path))
|
|
|
|
throw DB::Exception(
|
2022-06-21 14:40:22 +00:00
|
|
|
DB::ErrorCodes::BAD_ARGUMENTS, "Path {} must be inside disk path {}", full_path, disk_path);
|
2022-06-06 11:14:50 +00:00
|
|
|
|
2022-06-21 14:40:22 +00:00
|
|
|
return path;
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|