2007-01-14 12:32:44 +00:00
|
|
|
#include "common-opts.hh"
|
|
|
|
#include "../libmain/shared.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
bool parseOptionArg(const string & arg, Strings::iterator & i,
|
|
|
|
const Strings::iterator & argsEnd, EvalState & state,
|
2010-04-07 15:47:06 +00:00
|
|
|
Bindings & autoArgs)
|
2007-01-14 12:32:44 +00: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 15:47:06 +00:00
|
|
|
|
2010-10-24 19:52:33 +00:00
|
|
|
/* !!! check for duplicates! */
|
2010-10-22 14:47:42 +00:00
|
|
|
Value * v = state.allocValue();
|
2010-10-24 19:52:33 +00:00
|
|
|
autoArgs.push_back(Attr(state.symbols.create(name), v));
|
2010-04-07 15:47:06 +00:00
|
|
|
|
|
|
|
if (arg == "--arg")
|
2011-08-06 13:02:55 +00:00
|
|
|
state.mkThunk_(*v, state.parseExprFromString(value, absPath(".")));
|
2010-04-07 15:47:06 +00:00
|
|
|
else
|
2010-10-22 14:47:42 +00:00
|
|
|
mkString(*v, value);
|
2010-10-24 19:52:33 +00:00
|
|
|
|
|
|
|
autoArgs.sort(); // !!! inefficient
|
|
|
|
|
2007-01-14 12:32:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|