mirror of
https://github.com/NixOS/nix.git
synced 2025-12-13 12:31:04 +01:00
Merge pull request #14708 from obsidiansystems/version-path-info-outer
Make `nix path-info` follow the JSON guidelines
This commit is contained in:
commit
a4fc3863dd
9 changed files with 65 additions and 30 deletions
|
|
@ -41,10 +41,14 @@ pathInfoToJSON(Store & store, const StorePathSet & storePaths, bool showClosureS
|
|||
{
|
||||
json::object_t jsonAllObjects = json::object();
|
||||
|
||||
auto makeKey = [&](const StorePath & path) {
|
||||
return format == PathInfoJsonFormat::V1 ? store.printStorePath(path) : std::string(path.to_string());
|
||||
};
|
||||
|
||||
for (auto & storePath : storePaths) {
|
||||
json jsonObject;
|
||||
|
||||
std::string key = store.printStorePath(storePath);
|
||||
std::string key = makeKey(storePath);
|
||||
|
||||
try {
|
||||
auto info = store.queryPathInfo(storePath);
|
||||
|
|
@ -52,7 +56,7 @@ pathInfoToJSON(Store & store, const StorePathSet & storePaths, bool showClosureS
|
|||
// `storePath` has the representation `<hash>-x` rather than
|
||||
// `<hash>-<name>` in case of binary-cache stores & `--all` because we don't
|
||||
// know the name yet until we've read the NAR info.
|
||||
key = store.printStorePath(info->path);
|
||||
key = makeKey(info->path);
|
||||
|
||||
jsonObject = info->toJSON(format == PathInfoJsonFormat::V1 ? &store : nullptr, true, format);
|
||||
|
||||
|
|
@ -87,7 +91,16 @@ pathInfoToJSON(Store & store, const StorePathSet & storePaths, bool showClosureS
|
|||
|
||||
jsonAllObjects[key] = std::move(jsonObject);
|
||||
}
|
||||
return jsonAllObjects;
|
||||
|
||||
if (format == PathInfoJsonFormat::V1) {
|
||||
return jsonAllObjects;
|
||||
} else {
|
||||
return {
|
||||
{"version", format},
|
||||
{"storeDir", store.storeDir},
|
||||
{"info", std::move(jsonAllObjects)},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
struct CmdPathInfo : StorePathsCommand, MixJSON
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue