Skip to content

Commit

Permalink
nix flake show: add the description if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kjeremy committed Jun 27, 2024
1 parent b44909a commit 4c01250
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/nix/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1234,25 +1234,30 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
auto showDerivation = [&]()
{
auto name = visitor.getAttr(state->sName)->getString();
std::optional<std::string> description;
if (auto aMeta = visitor.maybeGetAttr(state->sMeta)) {
if (auto aDescription = aMeta->maybeGetAttr(state->sDescription))
description = aDescription->getString();
}

if (json) {
std::optional<std::string> description;
if (auto aMeta = visitor.maybeGetAttr(state->sMeta)) {
if (auto aDescription = aMeta->maybeGetAttr(state->sDescription))
description = aDescription->getString();
}
j.emplace("type", "derivation");
j.emplace("name", name);
if (description)
j.emplace("description", *description);
} else {
logger->cout("%s: %s '%s'",
headerPrefix,
auto type =
attrPath.size() == 2 && attrPathS[0] == "devShell" ? "development environment" :
attrPath.size() >= 2 && attrPathS[0] == "devShells" ? "development environment" :
attrPath.size() == 3 && attrPathS[0] == "checks" ? "derivation" :
attrPath.size() >= 1 && attrPathS[0] == "hydraJobs" ? "derivation" :
"package",
name);
"package";
if (description) {
logger->cout("%s: %s '%s' - '%s'", headerPrefix, type, name, *description);
}
else {
logger->cout("%s: %s '%s'", headerPrefix, type, name);
}
}
};

Expand Down

0 comments on commit 4c01250

Please sign in to comment.