diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index 812f8b446..4082ddb0d 100644 --- a/lix/libcmd/command.cc +++ b/lix/libcmd/command.cc @@ -75,6 +75,15 @@ CopyCommand::CopyCommand() }); } +void CopyCommand::run() +{ + if (requireStore && srcUri.empty() && dstUri.empty()) { + throw UsageError("you must pass '--from' and/or '--to'"); + } + + StoreCommand::run(); +} + ref CopyCommand::createStore(AsyncIoRoot & in) { return srcUri.empty() ? StoreCommand::createStore(in) : in.blockOn(openStore(srcUri)); @@ -82,9 +91,6 @@ ref CopyCommand::createStore(AsyncIoRoot & in) ref CopyCommand::getDstStore() { - if (srcUri.empty() && dstUri.empty()) - throw UsageError("you must pass '--from' and/or '--to'"); - return aio().blockOn(dstUri.empty() ? openStore() : openStore(dstUri)); } diff --git a/lix/libcmd/command.hh b/lix/libcmd/command.hh index da8cc4934..9b242e159 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -56,9 +56,11 @@ private: struct CopyCommand : virtual StoreCommand { std::string srcUri, dstUri; + bool requireStore = true; CopyCommand(); + void run() override; ref createStore(AsyncIoRoot & in) override; ref getDstStore(); diff --git a/lix/nix/make-content-addressed.cc b/lix/nix/make-content-addressed.cc index 9074e6f3b..4912a6556 100644 --- a/lix/nix/make-content-addressed.cc +++ b/lix/nix/make-content-addressed.cc @@ -12,6 +12,7 @@ struct CmdMakeContentAddressed : virtual CopyCommand, virtual StorePathsCommand, CmdMakeContentAddressed() { realiseMode = Realise::Outputs; + requireStore = false; } std::string description() override @@ -28,7 +29,7 @@ struct CmdMakeContentAddressed : virtual CopyCommand, virtual StorePathsCommand, void run(ref srcStore, StorePaths && storePaths) override { - auto dstStore = aio().blockOn(dstUri.empty() ? openStore() : openStore(dstUri)); + auto dstStore = getDstStore(); auto remappings = aio().blockOn(makeContentAddressed(*srcStore, *dstStore, StorePathSet(storePaths.begin(), storePaths.end())));