mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 22:46:16 +02:00
Load files specified on the command line
For example: $ nix-repl '<nixpkgs>' '<nixos>' Welcome to Nix version 1.6pre3215_2c1ecf8. Type :? for help. Loading ‘<nixpkgs>’... Added 3337 variables. Loading ‘<nixos>’... Added 7 variables. nix-repl>
This commit is contained in:
parent
b5944ac4ff
commit
cf4c29d90a
1 changed files with 24 additions and 12 deletions
36
nix-repl.cc
36
nix-repl.cc
|
@ -31,8 +31,9 @@ struct NixRepl
|
||||||
int displ;
|
int displ;
|
||||||
|
|
||||||
NixRepl();
|
NixRepl();
|
||||||
void mainLoop();
|
void mainLoop(const Strings & args);
|
||||||
void processLine(string line);
|
void processLine(string line);
|
||||||
|
void loadFile(const Path & path);
|
||||||
void addAttrsToScope(Value & attrs);
|
void addAttrsToScope(Value & attrs);
|
||||||
void addVarToScope(const Symbol & name, Value * v);
|
void addVarToScope(const Symbol & name, Value * v);
|
||||||
Expr * parseString(string s);
|
Expr * parseString(string s);
|
||||||
|
@ -110,9 +111,15 @@ NixRepl::NixRepl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NixRepl::mainLoop()
|
void NixRepl::mainLoop(const Strings & args)
|
||||||
{
|
{
|
||||||
std::cerr << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;
|
std::cout << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;
|
||||||
|
|
||||||
|
foreach (Strings::const_iterator, i, args) {
|
||||||
|
std::cout << format("Loading ‘%1%’...") % *i << std::endl;
|
||||||
|
loadFile(*i);
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
using_history();
|
using_history();
|
||||||
read_history(0);
|
read_history(0);
|
||||||
|
@ -150,12 +157,7 @@ void NixRepl::processLine(string line)
|
||||||
|
|
||||||
else if (command == ":l") {
|
else if (command == ":l") {
|
||||||
state.resetFileCache();
|
state.resetFileCache();
|
||||||
Path path = lookupFileArg(state, removeWhitespace(string(line, 2)));
|
loadFile(removeWhitespace(string(line, 2)));
|
||||||
Value v, v2;
|
|
||||||
state.evalFile(path, v);
|
|
||||||
Bindings bindings;
|
|
||||||
state.autoCallFunction(bindings, v, v2);
|
|
||||||
addAttrsToScope(v2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":t") {
|
else if (command == ":t") {
|
||||||
|
@ -202,12 +204,22 @@ void NixRepl::processLine(string line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NixRepl::loadFile(const Path & path)
|
||||||
|
{
|
||||||
|
Value v, v2;
|
||||||
|
state.evalFile(lookupFileArg(state, path), v);
|
||||||
|
Bindings bindings;
|
||||||
|
state.autoCallFunction(bindings, v, v2);
|
||||||
|
addAttrsToScope(v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NixRepl::addAttrsToScope(Value & attrs)
|
void NixRepl::addAttrsToScope(Value & attrs)
|
||||||
{
|
{
|
||||||
state.forceAttrs(attrs);
|
state.forceAttrs(attrs);
|
||||||
foreach (Bindings::iterator, i, *attrs.attrs)
|
foreach (Bindings::iterator, i, *attrs.attrs)
|
||||||
addVarToScope(i->name, i->value);
|
addVarToScope(i->name, i->value);
|
||||||
std::cout << format("added %1% variables") % attrs.attrs->size() << std::endl;
|
std::cout << format("Added %1% variables.") % attrs.attrs->size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,8 +245,8 @@ void NixRepl::evalString(string s, Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void run(nix::Strings args)
|
void run(Strings args)
|
||||||
{
|
{
|
||||||
NixRepl repl;
|
NixRepl repl;
|
||||||
repl.mainLoop();
|
repl.mainLoop(args);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue