From 4dda1f92aae05dd9d633152458d65a3815bcd03c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 17 Jan 2022 19:45:21 +0100 Subject: Add command 'nix store copy-log' Fixes #5222. --- src/libcmd/command.cc | 67 +++++++++++++++++++++++---------------------------- src/libcmd/command.hh | 30 ++++++++++------------- 2 files changed, 43 insertions(+), 54 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 5e6d4a857..6d183dfad 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,6 +54,36 @@ void StoreCommand::run() run(getStore()); } +CopyCommand::CopyCommand() +{ + addFlag({ + .longName = "from", + .description = "URL of the source Nix store.", + .labels = {"store-uri"}, + .handler = {&srcUri}, + }); + + addFlag({ + .longName = "to", + .description = "URL of the destination Nix store.", + .labels = {"store-uri"}, + .handler = {&dstUri}, + }); +} + +ref CopyCommand::createStore() +{ + return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); +} + +ref CopyCommand::getDstStore() +{ + if (srcUri.empty() && dstUri.empty()) + throw UsageError("you must pass '--from' and/or '--to'"); + + return dstUri.empty() ? openStore() : openStore(dstUri); +} + EvalCommand::EvalCommand() { } @@ -159,43 +189,6 @@ void StorePathsCommand::run(ref store, BuiltPaths && paths) run(store, std::move(sorted)); } -CopyCommand::CopyCommand() - : BuiltPathsCommand(true) -{ - addFlag({ - .longName = "from", - .description = "URL of the source Nix store.", - .labels = {"store-uri"}, - .handler = {&srcUri}, - }); - - addFlag({ - .longName = "to", - .description = "URL of the destination Nix store.", - .labels = {"store-uri"}, - .handler = {&dstUri}, - }); -} - -ref CopyCommand::createStore() -{ - return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); -} - -void CopyCommand::run(ref store) -{ - if (srcUri.empty() && dstUri.empty()) - throw UsageError("you must pass '--from' and/or '--to'"); - - BuiltPathsCommand::run(store); -} - -void CopyCommand::run(ref srcStore, BuiltPaths && paths) -{ - ref dstStore = dstUri.empty() ? openStore() : openStore(dstUri); - run(srcStore, dstStore, std::move(paths)); -} - void StorePathCommand::run(ref store, std::vector && storePaths) { if (storePaths.size() != 1) diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 0c3e29e25..bd2a0a7ee 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -43,6 +43,19 @@ private: std::shared_ptr _store; }; +/* A command that copies something between `--from` and `--to` + stores. */ +struct CopyCommand : virtual StoreCommand +{ + std::string srcUri, dstUri; + + CopyCommand(); + + ref createStore() override; + + ref getDstStore(); +}; + struct EvalCommand : virtual StoreCommand, MixEvalArgs { EvalCommand(); @@ -176,23 +189,6 @@ public: bool useDefaultInstallables() override { return !all; } }; -/* A command that copies something between `--from` and `--to` - stores. */ -struct CopyCommand : virtual BuiltPathsCommand -{ - std::string srcUri, dstUri; - - CopyCommand(); - - ref createStore() override; - - void run(ref store) override; - - void run(ref srcStore, BuiltPaths && paths) override; - - virtual void run(ref srcStore, ref dstStore, BuiltPaths && paths) = 0; -}; - struct StorePathsCommand : public BuiltPathsCommand { StorePathsCommand(bool recursive = false); -- cgit v1.2.3