ClickHouse/programs/disks/CommandMkDir.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.0 KiB
C++
Raw Normal View History

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
{
class CommandMkDir final : public ICommand
2022-09-02 17:30:35 +00:00
{
public:
CommandMkDir()
{
command_name = "mkdir";
2024-06-10 16:17:36 +00:00
description = "Creates a directory";
options_description.add_options()("parents", "recursively create directories")(
"path", po::value<String>(), "the path on which directory should be created (mandatory, positional)");
2024-05-27 11:44:45 +00:00
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
{
bool recursive = options.count("parents");
2024-05-27 11:44:45 +00:00
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_shared<DB::CommandMkDir>();
2022-09-02 17:30:35 +00:00
}
2024-05-27 11:44:45 +00:00
}