mirror of
https://github.com/NixOS/nix
synced 2025-06-25 19:01:16 +02: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 20 variables in order to avoid excessive prints. https://github.com/NixOS/nix/issues/11404
This commit is contained in:
parent
2afc84fddf
commit
3c9b9b13af
2 changed files with 47 additions and 1 deletions
|
@ -813,6 +813,25 @@ void NixRepl::addAttrsToScope(Value & attrs)
|
|||
staticEnv->sort();
|
||||
staticEnv->deduplicate();
|
||||
notice("Added %1% variables.", attrs.attrs()->size());
|
||||
|
||||
const int max_print = 20;
|
||||
int counter = 0;
|
||||
std::ostringstream loaded;
|
||||
for (auto & i : attrs.attrs()->lexicographicOrder(state->symbols)) {
|
||||
if (counter >= max_print)
|
||||
break;
|
||||
|
||||
if (counter > 0)
|
||||
loaded << ", ";
|
||||
|
||||
printIdentifier(loaded, state->symbols[i->name]);
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
notice("%1%", loaded.str());
|
||||
|
||||
if (attrs.attrs()->size() > max_print)
|
||||
notice("... and %1% more", attrs.attrs()->size() - max_print);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue