Merge "nix flake show: add the description if it exists" into main
This commit is contained in:
commit
9eb374dc6d
|
@ -70,10 +70,17 @@ horrors:
|
|||
iFreilicht:
|
||||
github: iFreilicht
|
||||
|
||||
isabelroses:
|
||||
forgejo: isabelroses
|
||||
github: isabelroses
|
||||
|
||||
jade:
|
||||
forgejo: jade
|
||||
github: lf-
|
||||
|
||||
kjeremy:
|
||||
github: kjeremy
|
||||
|
||||
kloenk:
|
||||
forgejo: kloenk
|
||||
github: kloenk
|
||||
|
|
37
doc/manual/rl-next/nix-flake-show-description.md
Normal file
37
doc/manual/rl-next/nix-flake-show-description.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
synopsis: "Lix will now show the package descriptions in when running `nix flake show`."
|
||||
cls: [1540]
|
||||
issues: []
|
||||
credits: [kjeremy, isabelroses]
|
||||
category: Improvements
|
||||
---
|
||||
|
||||
When running `nix flake show`, Lix will now show the package descriptions, if they exist.
|
||||
|
||||
Before:
|
||||
|
||||
```shell
|
||||
$ nix flake show
|
||||
path:/home/isabel/dev/lix-show?lastModified=1721736108&narHash=sha256-Zo8HP1ur7Q2b39hKUEG8EAh/opgq8xJ2jvwQ/htwO4Q%3D
|
||||
└───packages
|
||||
└───x86_64-linux
|
||||
├───aNoDescription: package 'simple'
|
||||
├───bOneLineDescription: package 'simple'
|
||||
├───cMultiLineDescription: package 'simple'
|
||||
├───dLongDescription: package 'simple'
|
||||
└───eEmptyDescription: package 'simple'
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```shell
|
||||
$ nix flake show
|
||||
path:/home/isabel/dev/lix-show?lastModified=1721736108&narHash=sha256-Zo8HP1ur7Q2b39hKUEG8EAh/opgq8xJ2jvwQ/htwO4Q%3D
|
||||
└───packages
|
||||
└───x86_64-linux
|
||||
├───aNoDescription: package 'simple'
|
||||
├───bOneLineDescription: package 'simple' - 'one line'
|
||||
├───cMultiLineDescription: package 'simple' - 'line one'
|
||||
├───dLongDescription: package 'simple' - 'abcdefghijklmnopqrstuvwxyz'
|
||||
└───eEmptyDescription: package 'simple'
|
||||
```
|
|
@ -20,6 +20,7 @@
|
|||
doxygen,
|
||||
editline-lix ? __forDefaults.editline-lix,
|
||||
editline,
|
||||
expect,
|
||||
git,
|
||||
gtest,
|
||||
jq,
|
||||
|
@ -254,6 +255,8 @@ stdenv.mkDerivation (finalAttrs: {
|
|||
++ lib.optional (hostPlatform.canExecute buildPlatform) aws-sdk-cpp-nix
|
||||
++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs;
|
||||
|
||||
nativeCheckInputs = [ expect ];
|
||||
|
||||
checkInputs = [
|
||||
gtest
|
||||
rapidcheck
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "registry.hh"
|
||||
#include "eval-cache.hh"
|
||||
#include "markdown.hh"
|
||||
#include "terminal.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <queue>
|
||||
|
@ -1225,25 +1226,42 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
auto showDerivation = [&]()
|
||||
{
|
||||
auto name = visitor.getAttr(state->sName)->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();
|
||||
}
|
||||
|
||||
if (json) {
|
||||
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 && !description->empty()) {
|
||||
// Trim the string and only display the first line of the description.
|
||||
auto desc = nix::trim(*description);
|
||||
auto firstLineDesc = desc.substr(0, desc.find('\n'));
|
||||
|
||||
std::string output = fmt("%s: %s '%s' - '%s'", headerPrefix, type, name, firstLineDesc);
|
||||
if (output.size() > getWindowSize().second) {
|
||||
// we resize to 4 less then the window size to account for the "...'" we append to
|
||||
// the final string, we also include the ' since that is removed when we truncate the string
|
||||
output.resize(getWindowSize().second - 4);
|
||||
output.append("...'");
|
||||
}
|
||||
|
||||
logger->cout("%s", output.c_str());
|
||||
}
|
||||
else {
|
||||
logger->cout("%s: %s '%s'", headerPrefix, type, name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -85,3 +85,31 @@ assert show_output.legacyPackages.${builtins.currentSystem}.AAAAAASomeThingsFail
|
|||
assert show_output.legacyPackages.${builtins.currentSystem}.simple.name == "simple";
|
||||
true
|
||||
'
|
||||
|
||||
cat >flake.nix<<EOF
|
||||
{
|
||||
outputs = inputs: {
|
||||
packages.$system = {
|
||||
aNoDescription = import ./simple.nix;
|
||||
bOneLineDescription = import ./simple.nix // { meta.description = "one line"; };
|
||||
cMultiLineDescription = import ./simple.nix // { meta.description = ''
|
||||
line one
|
||||
line two
|
||||
''; };
|
||||
dLongDescription = import ./simple.nix // { meta.description = ''
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
''; };
|
||||
eEmptyDescription = import ./simple.nix // { meta.description = ""; };
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
unbuffer sh -c '
|
||||
stty rows 20 cols 100
|
||||
nix flake show > show-output.txt
|
||||
'
|
||||
test "$(awk -F '[:] ' '/aNoDescription/{print $NF}' ./show-output.txt)" = "package 'simple'"
|
||||
test "$(awk -F '[:] ' '/bOneLineDescription/{print $NF}' ./show-output.txt)" = "package 'simple' - 'one line'"
|
||||
test "$(awk -F '[:] ' '/cMultiLineDescription/{print $NF}' ./show-output.txt)" = "package 'simple' - 'line one'"
|
||||
test "$(awk -F '[:] ' '/dLongDescription/{print $NF}' ./show-output.txt)" = "package 'simple' - 'abcdefghijklmnopqrs...'"
|
||||
test "$(awk -F '[:] ' '/eEmptyDescription/{print $NF}' ./show-output.txt)" = "package 'simple'"
|
||||
|
|
Loading…
Reference in a new issue