mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 16:23:02 +00:00
Merge pull request #5883 from fzakaria/faridzakaria/check-meta
Check for `--meta` before emitting it for `--json`
This commit is contained in:
commit
d023903b6f
@ -907,7 +907,7 @@ static VersionDiff compareVersionAgainstSet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void queryJSON(Globals & globals, vector<DrvInfo> & elems, bool printOutPath)
|
static void queryJSON(Globals & globals, vector<DrvInfo> & elems, bool printOutPath, bool printMeta)
|
||||||
{
|
{
|
||||||
JSONObject topObj(cout, true);
|
JSONObject topObj(cout, true);
|
||||||
for (auto & i : elems) {
|
for (auto & i : elems) {
|
||||||
@ -927,17 +927,19 @@ static void queryJSON(Globals & globals, vector<DrvInfo> & elems, bool printOutP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject metaObj = pkgObj.object("meta");
|
if (printMeta) {
|
||||||
StringSet metaNames = i.queryMetaNames();
|
JSONObject metaObj = pkgObj.object("meta");
|
||||||
for (auto & j : metaNames) {
|
StringSet metaNames = i.queryMetaNames();
|
||||||
auto placeholder = metaObj.placeholder(j);
|
for (auto & j : metaNames) {
|
||||||
Value * v = i.queryMeta(j);
|
auto placeholder = metaObj.placeholder(j);
|
||||||
if (!v) {
|
Value * v = i.queryMeta(j);
|
||||||
printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j);
|
if (!v) {
|
||||||
placeholder.write(nullptr);
|
printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j);
|
||||||
} else {
|
placeholder.write(nullptr);
|
||||||
PathSet context;
|
} else {
|
||||||
printValueAsJSON(*globals.state, true, *v, noPos, placeholder, context);
|
PathSet context;
|
||||||
|
printValueAsJSON(*globals.state, true, *v, noPos, placeholder, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1043,7 +1045,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||||||
|
|
||||||
/* Print the desired columns, or XML output. */
|
/* Print the desired columns, or XML output. */
|
||||||
if (jsonOutput) {
|
if (jsonOutput) {
|
||||||
queryJSON(globals, elems, printOutPath);
|
queryJSON(globals, elems, printOutPath, printMeta);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user