nix flake show: add the description if it exists

This commit is contained in:
Jeremy Kolb 2024-06-27 15:35:55 -04:00
parent 5a6e28e166
commit 547e808a75

View file

@ -1243,25 +1243,30 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
auto showDerivation = [&]() auto showDerivation = [&]()
{ {
auto name = visitor.getAttr(state->sName)->getString(); 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) { 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("type", "derivation");
j.emplace("name", name); j.emplace("name", name);
if (description) if (description)
j.emplace("description", *description); j.emplace("description", *description);
} else { } else {
logger->cout("%s: %s '%s'", auto type =
headerPrefix,
attrPath.size() == 2 && attrPathS[0] == "devShell" ? "development environment" : attrPath.size() == 2 && attrPathS[0] == "devShell" ? "development environment" :
attrPath.size() >= 2 && attrPathS[0] == "devShells" ? "development environment" : attrPath.size() >= 2 && attrPathS[0] == "devShells" ? "development environment" :
attrPath.size() == 3 && attrPathS[0] == "checks" ? "derivation" : attrPath.size() == 3 && attrPathS[0] == "checks" ? "derivation" :
attrPath.size() >= 1 && attrPathS[0] == "hydraJobs" ? "derivation" : attrPath.size() >= 1 && attrPathS[0] == "hydraJobs" ? "derivation" :
"package", "package";
name); if (description) {
logger->cout("%s: %s '%s' - '%s'", headerPrefix, type, name, *description);
}
else {
logger->cout("%s: %s '%s'", headerPrefix, type, name);
}
} }
}; };