1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 12:10:59 +01:00

Make store setting and store flags use StoreReference

This commit is contained in:
John Ericson 2024-01-24 11:05:26 -05:00
parent 4a19f4a866
commit a7c841f704
35 changed files with 269 additions and 105 deletions

View file

@ -75,28 +75,32 @@ CopyCommand::CopyCommand()
.longName = "from",
.description = "URL of the source Nix store.",
.labels = {"store-uri"},
.handler = {&srcUri},
.handler = {[&](std::string storeUri) {
srcUri = StoreReference::parse(storeUri);
}},
});
addFlag({
.longName = "to",
.description = "URL of the destination Nix store.",
.labels = {"store-uri"},
.handler = {&dstUri},
.handler = {[&](std::string storeUri) {
dstUri = StoreReference::parse(storeUri);
}},
});
}
ref<Store> CopyCommand::createStore()
{
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
return !srcUri ? StoreCommand::createStore() : openStore(*srcUri);
}
ref<Store> CopyCommand::getDstStore()
{
if (srcUri.empty() && dstUri.empty())
if (!srcUri && !dstUri)
throw UsageError("you must pass '--from' and/or '--to'");
return dstUri.empty() ? openStore() : openStore(dstUri);
return !dstUri ? openStore() : openStore(*dstUri);
}
EvalCommand::EvalCommand()

View file

@ -62,7 +62,7 @@ private:
*/
struct CopyCommand : virtual StoreCommand
{
std::string srcUri, dstUri;
std::optional<StoreReference> srcUri, dstUri;
CopyCommand();

View file

@ -164,7 +164,9 @@ MixEvalArgs::MixEvalArgs()
)",
.category = category,
.labels = {"store-url"},
.handler = {&evalStoreUrl},
.handler = {[&](std::string s) {
evalStoreUrl = StoreReference::parse(s);
}},
});
}

View file

@ -5,6 +5,7 @@
#include "canon-path.hh"
#include "common-args.hh"
#include "search-path.hh"
#include "store-reference.hh"
#include <filesystem>
@ -25,7 +26,7 @@ struct MixEvalArgs : virtual Args, virtual MixRepair
LookupPath lookupPath;
std::optional<std::string> evalStoreUrl;
std::optional<StoreReference> evalStoreUrl;
private:
struct AutoArgExpr { std::string expr; };