aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/command.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-01-17 13:58:26 +0100
committerEelco Dolstra <edolstra@gmail.com>2022-01-18 14:08:49 +0100
commit6448ea84ab537600d3f350867063bc305b3bb910 (patch)
tree88b6bd50459b3d0f617d32855c0a757716f39b43 /src/libcmd/command.cc
parentf6f0bcf11ff79213f5ffa58d0e490901b2d3ce58 (diff)
Factor out --from / --to logic
Diffstat (limited to 'src/libcmd/command.cc')
-rw-r--r--src/libcmd/command.cc54
1 files changed, 47 insertions, 7 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc
index 429cd32cc..5e6d4a857 100644
--- a/src/libcmd/command.cc
+++ b/src/libcmd/command.cc
@@ -73,13 +73,16 @@ ref<Store> EvalCommand::getEvalStore()
ref<EvalState> EvalCommand::getEvalState()
{
- if (!evalState) evalState =
-#if HAVE_BOEHMGC
- std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
-#else
- std::make_shared<EvalState>(
-#endif
- searchPath, getEvalStore(), getStore());
+ if (!evalState)
+ evalState =
+ #if HAVE_BOEHMGC
+ std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
+ searchPath, getEvalStore(), getStore())
+ #else
+ std::make_shared<EvalState>(
+ searchPath, getEvalStore(), getStore())
+ #endif
+ ;
return ref<EvalState>(evalState);
}
@@ -156,6 +159,43 @@ void StorePathsCommand::run(ref<Store> 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<Store> CopyCommand::createStore()
+{
+ return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
+}
+
+void CopyCommand::run(ref<Store> store)
+{
+ if (srcUri.empty() && dstUri.empty())
+ throw UsageError("you must pass '--from' and/or '--to'");
+
+ BuiltPathsCommand::run(store);
+}
+
+void CopyCommand::run(ref<Store> srcStore, BuiltPaths && paths)
+{
+ ref<Store> dstStore = dstUri.empty() ? openStore() : openStore(dstUri);
+ run(srcStore, dstStore, std::move(paths));
+}
+
void StorePathCommand::run(ref<Store> store, std::vector<StorePath> && storePaths)
{
if (storePaths.size() != 1)