Check for --meta before emitting it for --json

Check that the meta flag is present when emitting JSON query information
for `nix-env`.

fixes #5882
This commit is contained in:
Farid Zakaria 2022-01-06 14:40:02 -08:00
parent f71d84672b
commit e36fdbbfd9

View file

@ -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,6 +927,7 @@ static void queryJSON(Globals & globals, vector<DrvInfo> & elems, bool printOutP
} }
} }
if (printMeta) {
JSONObject metaObj = pkgObj.object("meta"); JSONObject metaObj = pkgObj.object("meta");
StringSet metaNames = i.queryMetaNames(); StringSet metaNames = i.queryMetaNames();
for (auto & j : metaNames) { for (auto & j : metaNames) {
@ -942,6 +943,7 @@ static void queryJSON(Globals & globals, vector<DrvInfo> & elems, bool printOutP
} }
} }
} }
}
static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
@ -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;
} }