aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-07-30 11:43:45 +0200
committerGitHub <noreply@github.com>2019-07-30 11:43:45 +0200
commit41d010fff6109184a9b5e31c111aeea79cfcf76f (patch)
treea9829c77d88861565c081f7316b9df4a25b72162 /src
parent219d645987a82ee5aebf5a9ab28aa518d0615af0 (diff)
parentcd933b22d2041b7efc348dcc09ff255967ffc663 (diff)
Merge pull request #3009 from codedownio/add-pname-and-version-to-json
Add pname and version to nix-env -q --json
Diffstat (limited to 'src')
-rw-r--r--src/nix-env/nix-env.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 56ed75dae..87b2e43f0 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -860,7 +860,10 @@ static void queryJSON(Globals & globals, vector<DrvInfo> & elems)
for (auto & i : elems) {
JSONObject pkgObj = topObj.object(i.attrPath);
- pkgObj.attr("name", i.queryName());
+ auto drvName = DrvName(i.queryName());
+ pkgObj.attr("name", drvName.fullName);
+ pkgObj.attr("pname", drvName.name);
+ pkgObj.attr("version", drvName.version);
pkgObj.attr("system", i.querySystem());
JSONObject metaObj = pkgObj.object("meta");
@@ -1026,10 +1029,14 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
else if (printAttrPath)
columns.push_back(i.attrPath);
- if (xmlOutput)
- attrs["name"] = i.queryName();
- else if (printName)
+ if (xmlOutput) {
+ auto drvName = DrvName(i.queryName());
+ attrs["name"] = drvName.fullName;
+ attrs["pname"] = drvName.name;
+ attrs["version"] = drvName.version;
+ } else if (printName) {
columns.push_back(i.queryName());
+ }
if (compareVersions) {
/* Compare this element against the versions of the