diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-09-06T13·20+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-09-06T13·20+0200 |
commit | cf4c29d90a1b0ec7f8cd7f0c5258be63a2e02058 (patch) | |
tree | c8d3936069437c627de4d6a1cfebb90172f717dc /nix-repl.cc | |
parent | b5944ac4ffffde7f52d0bbe3f4a2d53bba70bb66 (diff) |
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>
Diffstat (limited to 'nix-repl.cc')
-rw-r--r-- | nix-repl.cc | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/nix-repl.cc b/nix-repl.cc index 838928b35dde..2ef23faa585a 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -31,8 +31,9 @@ struct NixRepl int displ; NixRepl(); - void mainLoop(); + void mainLoop(const Strings & args); void processLine(string line); + void loadFile(const Path & path); void addAttrsToScope(Value & attrs); void addVarToScope(const Symbol & name, Value * v); 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(); read_history(0); @@ -150,12 +157,7 @@ void NixRepl::processLine(string line) else if (command == ":l") { state.resetFileCache(); - Path path = lookupFileArg(state, removeWhitespace(string(line, 2))); - Value v, v2; - state.evalFile(path, v); - Bindings bindings; - state.autoCallFunction(bindings, v, v2); - addAttrsToScope(v2); + loadFile(removeWhitespace(string(line, 2))); } 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) { state.forceAttrs(attrs); foreach (Bindings::iterator, i, *attrs.attrs) 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; - repl.mainLoop(); + repl.mainLoop(args); } |