cq: improve derivation printing configuration
Change-Id: I7f16afa921cf2a33f750cb0f5cc53fa36a6a6964
This commit is contained in:
+4
-5
@@ -210,13 +210,12 @@ struct NixRepl
|
||||
void printValue(std::ostream & str,
|
||||
Value & v,
|
||||
unsigned int maxDepth = std::numeric_limits<unsigned int>::max(),
|
||||
bool replDerivation = false)
|
||||
unsigned int derivationPathDepth = 0)
|
||||
{
|
||||
::nix::printValue(state, str, v, PrintOptions {
|
||||
.ansiColors = true,
|
||||
.force = true,
|
||||
.derivationPaths = !replDerivation,
|
||||
.replDerivation = replDerivation,
|
||||
.derivationPathDepth = derivationPathDepth,
|
||||
.maxDepth = maxDepth,
|
||||
.prettyIndent = 2,
|
||||
.errors = ErrorPrintBehavior::ThrowTopLevel,
|
||||
@@ -796,9 +795,9 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||
if (v.type() == nString) {
|
||||
std::cout << v.str();
|
||||
} else if (v.type() == nAttrs && state.isDerivation(v)) {
|
||||
printValue(std::cout, v, 2, true);
|
||||
printValue(std::cout, v, 2, 1);
|
||||
} else {
|
||||
printValue(std::cout, v, std::numeric_limits<unsigned int>::max());
|
||||
printValue(std::cout, v, std::numeric_limits<unsigned int>::max(), 0);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
@@ -48,16 +48,12 @@ struct PrintOptions
|
||||
bool force = false;
|
||||
|
||||
/**
|
||||
* If true and `force` is set, print derivations as
|
||||
* `«derivation /nix/store/...»` instead of as attribute sets.
|
||||
* Determines at what depth derivations start getting printed as paths.
|
||||
* When `force` is true and our print depth is greater than or equal to
|
||||
* this value, print derivations as `«derivation /nix/store/...»`
|
||||
* instead of as attribute sets.
|
||||
*/
|
||||
bool derivationPaths = false;
|
||||
|
||||
/**
|
||||
* If true, we are interactively printing a full derivation and should
|
||||
* switch back to printing paths as desired normally after the first entry.
|
||||
*/
|
||||
bool replDerivation = false;
|
||||
size_t derivationPathDepth = std::numeric_limits<size_t>::max();
|
||||
|
||||
/**
|
||||
* If true, track which values have been printed and skip them on
|
||||
|
||||
@@ -281,16 +281,13 @@ private:
|
||||
|
||||
void printAttrs(Value & v, size_t depth)
|
||||
{
|
||||
if (options.force && options.derivationPaths && state.isDerivation(v)) {
|
||||
bool shouldSimplifyDerivations = options.force && depth >= options.derivationPathDepth;
|
||||
bool isDerivation = state.isDerivation(v);
|
||||
if (shouldSimplifyDerivations && isDerivation) {
|
||||
printDerivation(v);
|
||||
} else if (seen && !v.attrs()->empty() && !seen->insert(v.attrs()).second) {
|
||||
printRepeated();
|
||||
} else if (depth < options.maxDepth || v.attrs()->empty()) {
|
||||
bool isPrintingReplDerivation = depth == 0 && options.replDerivation && state.isDerivation(v);
|
||||
if (isPrintingReplDerivation) {
|
||||
// Switch back to eliding paths if it was initially off.
|
||||
options.derivationPaths = true;
|
||||
}
|
||||
increaseIndent();
|
||||
output << "{";
|
||||
|
||||
@@ -331,7 +328,7 @@ private:
|
||||
output << " = ";
|
||||
|
||||
// Elide repeated drvAttrs attribute.
|
||||
if (isPrintingReplDerivation && i.first == "drvAttrs") {
|
||||
if (!shouldSimplifyDerivations && isDerivation && i.first == "drvAttrs") {
|
||||
state.forceValue(i.second->value, noPos);
|
||||
if (i.second->value.type() == ValueType::nAttrs) {
|
||||
printElided(i.second->value.attrs()->size(), "attribute", "attributes");
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption
|
||||
v,
|
||||
PrintOptions{
|
||||
.force = true,
|
||||
.derivationPaths = true,
|
||||
.derivationPathDepth = 0,
|
||||
.errors = ErrorPrintBehavior::ThrowTopLevel,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -450,7 +450,7 @@ TEST_F(ValuePrintingTests, ansiColorsDerivation)
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.force = true,
|
||||
.derivationPaths = true
|
||||
.derivationPathDepth = 0
|
||||
});
|
||||
|
||||
test(vAttrs,
|
||||
@@ -507,7 +507,7 @@ TEST_F(ValuePrintingTests, ansiColorsDerivationError)
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.force = true,
|
||||
.derivationPaths = true,
|
||||
.derivationPathDepth = 0,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user