2007-01-14 13:32:44 +01: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 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-10-24 21:52:33 +02:00
|
|
|
/* !!! check for duplicates! */
|
2010-10-22 16:47:42 +02:00
|
|
|
Value * v = state.allocValue();
|
2010-10-24 21:52:33 +02:00
|
|
|
autoArgs.push_back(Attr(state.symbols.create(name), v));
|
2010-04-07 17:47:06 +02:00
|
|
|
|
|
|
|
if (arg == "--arg")
|
2011-08-06 15:02:55 +02:00
|
|
|
state.mkThunk_(*v, state.parseExprFromString(value, absPath(".")));
|
2010-04-07 17:47:06 +02:00
|
|
|
else
|
2010-10-22 16:47:42 +02:00
|
|
|
mkString(*v, value);
|
2010-10-24 21:52:33 +02:00
|
|
|
|
|
|
|
autoArgs.sort(); // !!! inefficient
|
|
|
|
|
2007-01-14 13:32:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-06 18:05:24 +02:00
|
|
|
|
|
|
|
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
|
|
|
|
const Strings::iterator & argsEnd, EvalState & state)
|
|
|
|
{
|
|
|
|
if (arg != "-I") return false;
|
|
|
|
if (i == argsEnd) throw UsageError(format("`%1%' requires an argument") % arg);;
|
|
|
|
state.addToSearchPath(*i++);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 17:41:43 +01:00
|
|
|
Path lookupFileArg(EvalState & state, string s)
|
|
|
|
{
|
|
|
|
if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
|
|
|
|
Path p = state.findFile(s.substr(1, s.size() - 2));
|
|
|
|
if (p == "") throw Error(format("file `%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)") % p);
|
|
|
|
return p;
|
|
|
|
} else
|
|
|
|
return absPath(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-14 13:32:44 +01:00
|
|
|
}
|