#include #include "ICommand.h" #include #include #include #include namespace DB { class CommandWrite final : public ICommand { public: CommandWrite() { command_name = "write"; description = "Write a file from `path-from` to `path-to`"; options_description.add_options()("path-from", po::value(), "file from which we are reading, defaults to `stdin` (input from `stdin` is finished by Ctrl+D)")( "path-to", po::value(), "file to which we are writing (mandatory, positional)"); positional_options_description.add("path-to", 1); } void executeImpl(const CommandLineOptions & options, DisksClient & client) override { auto disk = client.getCurrentDiskWithPath(); std::optional path_from = getValueFromCommandLineOptionsWithOptional(options, "path-from"); String path_to = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow(options, "path-to")); auto in = [&]() -> std::unique_ptr { if (!path_from.has_value()) { return std::make_unique(STDIN_FILENO); } else { String relative_path_from = disk.getRelativeFromRoot(path_from.value()); return disk.getDisk()->readFile(relative_path_from, getReadSettings()); } }(); auto out = disk.getDisk()->writeFile(path_to); copyData(*in, *out); out->finalize(); } }; CommandPtr makeCommandWrite() { return std::make_shared(); } }