mirror of
https://github.com/NixOS/nix
synced 2024-10-18 00:16:11 -04:00
nix repl: Print which variables are just loaded
When we run `nix repl nixpkgs` we get "Added 6 variables". This is not useful as it doesn't tell us which variables the flake has exported to our global repl scope. This patch prints the name of each variable that was just loaded. We currently cap printing to 10 variables in order to avoid excessive prints. https://github.com/NixOS/nix/issues/11404
This commit is contained in:
parent
68ba6ff470
commit
e3c6451d5f
|
@ -791,6 +791,25 @@ void NixRepl::addAttrsToScope(Value & attrs)
|
||||||
staticEnv->sort();
|
staticEnv->sort();
|
||||||
staticEnv->deduplicate();
|
staticEnv->deduplicate();
|
||||||
notice("Added %1% variables.", attrs.attrs()->size());
|
notice("Added %1% variables.", attrs.attrs()->size());
|
||||||
|
|
||||||
|
const int max_print = 10;
|
||||||
|
int counter = 0;
|
||||||
|
std::string loaded;
|
||||||
|
for (auto & i : attrs.attrs()->lexicographicOrder(state->symbols)) {
|
||||||
|
if (counter >= max_print)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (counter > 0)
|
||||||
|
loaded += ", ";
|
||||||
|
|
||||||
|
loaded += state->symbols[i->name];
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
notice("- %1%", loaded);
|
||||||
|
|
||||||
|
if (attrs.attrs()->size() > max_print)
|
||||||
|
notice("... and %1% more", attrs.attrs()->size() - max_print);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,32 @@ foo + baz
|
||||||
' "3" \
|
' "3" \
|
||||||
./flake ./flake\#bar --experimental-features 'flakes'
|
./flake ./flake\#bar --experimental-features 'flakes'
|
||||||
|
|
||||||
|
testReplResponse $'
|
||||||
|
:a { a = 1; b = 2; longerName = 3; "with spaces" = 4; }
|
||||||
|
' 'Added 4 variables.
|
||||||
|
- a, b, longerName, with spaces
|
||||||
|
'
|
||||||
|
|
||||||
|
cat <<EOF > attribute-set.nix
|
||||||
|
{
|
||||||
|
a = 1;
|
||||||
|
b = 2;
|
||||||
|
longerName = 3;
|
||||||
|
"with spaces" = 4;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
testReplResponse '
|
||||||
|
:l ./attribute-set.nix
|
||||||
|
' 'Added 4 variables.
|
||||||
|
- a, b, longerName, with spaces
|
||||||
|
'
|
||||||
|
|
||||||
|
testReplResponseNoRegex $'
|
||||||
|
:a builtins.foldl\' (x: y: x // y) {} (map (x: { ${builtins.toString x} = x; }) (builtins.genList (x: x) 13))
|
||||||
|
' 'Added 13 variables.
|
||||||
|
- 0, 1, 10, 11, 12, 2, 3, 4, 5, 6
|
||||||
|
... and 3 more'
|
||||||
|
|
||||||
# Test the `:reload` mechansim with flakes:
|
# Test the `:reload` mechansim with flakes:
|
||||||
# - Eval `./flake#changingThing`
|
# - Eval `./flake#changingThing`
|
||||||
# - Modify the flake
|
# - Modify the flake
|
||||||
|
@ -302,6 +328,8 @@ runRepl () {
|
||||||
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \
|
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \
|
||||||
-e "s@$nixVersion@<nix version>@g" \
|
-e "s@$nixVersion@<nix version>@g" \
|
||||||
-e "s@Added [0-9]* variables@Added <number omitted> variables@g" \
|
-e "s@Added [0-9]* variables@Added <number omitted> variables@g" \
|
||||||
|
-e '/^- /d' \
|
||||||
|
-e '/\.\.\. and [0-9]* more/d' \
|
||||||
| grep -vF $'warning: you don\'t have Internet access; disabling some network-dependent features' \
|
| grep -vF $'warning: you don\'t have Internet access; disabling some network-dependent features' \
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue