mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 02:36:16 +02:00
Handle long strings, embedded new lines and empty descriptions
This commit is contained in:
parent
59b6aafadb
commit
f22cf1fd38
2 changed files with 23 additions and 6 deletions
|
@ -1261,12 +1261,23 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
attrPath.size() == 3 && attrPathS[0] == "checks" ? "derivation" :
|
||||
attrPath.size() >= 1 && attrPathS[0] == "hydraJobs" ? "derivation" :
|
||||
"package";
|
||||
if (description) {
|
||||
// Handle new lines in descriptions.
|
||||
auto index = description->find('\n');
|
||||
std::string_view sanitized_description(description->data(), index != std::string::npos ? index : description->size());
|
||||
if (description && !description->empty()) {
|
||||
// Trim the string and only display the first line of the description.
|
||||
auto trimmed = nix::trim(*description);
|
||||
auto newLinePos = trimmed.find('\n');
|
||||
auto length = newLinePos != std::string::npos ? newLinePos : trimmed.size();
|
||||
|
||||
logger->cout("%s: %s '%s' - '%s'", headerPrefix, type, name, sanitized_description);
|
||||
// If the string is too long then resize add ellipses
|
||||
std::string desc;
|
||||
if (length > 80) {
|
||||
trimmed.resize(80);
|
||||
desc = trimmed.append("...");
|
||||
}
|
||||
else {
|
||||
desc = trimmed.substr(0, length);
|
||||
}
|
||||
|
||||
logger->cout("%s: %s '%s' - '%s'", headerPrefix, type, name, desc);
|
||||
}
|
||||
else {
|
||||
logger->cout("%s: %s '%s'", headerPrefix, type, name);
|
||||
|
|
|
@ -98,6 +98,10 @@ cat >flake.nix<<EOF
|
|||
line one
|
||||
line two
|
||||
''; };
|
||||
dLongDescription = import ./simple.nix // { meta.description = ''
|
||||
01234567890123456789012345678901234567890123456789012345678901234567890123456789abcdefg
|
||||
''; };
|
||||
eEmptyDescription = import ./simple.nix // { meta.description = ""; };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -106,3 +110,5 @@ 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' - '01234567890123456789012345678901234567890123456789012345678901234567890123456789...'"
|
||||
test "$(awk -F '[:] ' '/eEmptyDescription/{print $NF}' ./show-output.txt)" = "package 'simple'"
|
||||
|
|
Loading…
Reference in a new issue