2007-01-14 13:32:44 +01:00
|
|
|
#include "common-opts.hh"
|
|
|
|
#include "../libmain/shared.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
#include "parser.hh"
|
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
bool parseOptionArg(const string & arg, Strings::iterator & i,
|
|
|
|
const Strings::iterator & argsEnd, EvalState & state,
|
2010-04-07 17:47:06 +02:00
|
|
|
Bindings & autoArgs)
|
2007-01-14 13:32:44 +01:00
|
|
|
{
|
|
|
|
if (arg != "--arg" && arg != "--argstr") return false;
|
|
|
|
|
|
|
|
UsageError error(format("`%1%' requires two arguments") % arg);
|
|
|
|
|
|
|
|
if (i == argsEnd) throw error;
|
|
|
|
string name = *i++;
|
|
|
|
if (i == argsEnd) throw error;
|
|
|
|
string value = *i++;
|
2010-04-07 17:47:06 +02:00
|
|
|
|
2010-05-07 14:11:05 +02:00
|
|
|
Value & v(autoArgs[state.symbols.create(name)].value);
|
2010-04-07 17:47:06 +02:00
|
|
|
|
|
|
|
if (arg == "--arg")
|
2010-05-18 12:36:37 +02:00
|
|
|
state.mkThunk_(v, parseExprFromString(state, value, absPath(".")));
|
2010-04-07 17:47:06 +02:00
|
|
|
else
|
|
|
|
mkString(v, value);
|
2007-01-14 13:32:44 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|