2022-09-02 17:30:35 +00:00
|
|
|
#include "ICommand.h"
|
2022-12-08 17:53:05 +00:00
|
|
|
|
2022-09-02 17:30:35 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2022-12-08 17:53:05 +00:00
|
|
|
#include <Common/TerminalSize.h>
|
2022-09-02 17:30:35 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-12-08 17:20:54 +00:00
|
|
|
class CommandMkDir final : public ICommand
|
2022-09-02 17:30:35 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CommandMkDir()
|
|
|
|
{
|
|
|
|
command_name = "mkdir";
|
2023-08-29 12:25:04 +00:00
|
|
|
description = "Create a directory";
|
2024-05-27 11:44:45 +00:00
|
|
|
options_description.add_options()("recursive", "recursively create directories")(
|
|
|
|
"path", po::value<String>(), "the path of listing (mandatory, positional)");
|
|
|
|
positional_options_description.add("path", 1);
|
2022-09-02 17:30:35 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
void executeImpl(const CommandLineOptions & options, DisksClient & client) override
|
2022-09-02 17:30:35 +00:00
|
|
|
{
|
2024-05-27 11:44:45 +00:00
|
|
|
bool recursive = options.count("recursive");
|
|
|
|
auto disk = client.getCurrentDiskWithPath();
|
2022-09-02 17:30:35 +00:00
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
String path = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path"));
|
2022-09-02 17:30:35 +00:00
|
|
|
|
|
|
|
if (recursive)
|
2024-05-27 11:44:45 +00:00
|
|
|
disk.getDisk()->createDirectories(path);
|
2022-09-02 17:30:35 +00:00
|
|
|
else
|
2024-05-27 11:44:45 +00:00
|
|
|
disk.getDisk()->createDirectory(path);
|
2022-09-02 17:30:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
CommandPtr makeCommandMkDir()
|
2022-09-02 17:30:35 +00:00
|
|
|
{
|
|
|
|
return std::make_unique<DB::CommandMkDir>();
|
|
|
|
}
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
}
|