about summary refs log tree commit diff
path: root/src/libexpr/common-opts.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/common-opts.cc')
-rw-r--r--src/libexpr/common-opts.cc45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/libexpr/common-opts.cc b/src/libexpr/common-opts.cc
index a3ea202e889e..2e8bb29c7dc2 100644
--- a/src/libexpr/common-opts.cc
+++ b/src/libexpr/common-opts.cc
@@ -6,40 +6,45 @@
 namespace nix {
 
 
-bool parseOptionArg(const string & arg, Strings::iterator & i,
-    const Strings::iterator & argsEnd, EvalState & state,
-    Bindings & autoArgs)
+bool parseAutoArgs(Strings::iterator & i,
+    const Strings::iterator & argsEnd, std::map<string, string> & res)
 {
+    string arg = *i;
     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++;
+    if (++i == argsEnd) throw error;
+    string name = *i;
+    if (++i == argsEnd) throw error;
+    string value = *i;
 
-    /* !!! check for duplicates! */
-    Value * v = state.allocValue();
-    autoArgs.push_back(Attr(state.symbols.create(name), v));
+    res[name] = (arg == "--arg" ? 'E' : 'S') + value;
 
-    if (arg == "--arg")
-        state.mkThunk_(*v, state.parseExprFromString(value, absPath(".")));
-    else
-        mkString(*v, value);
+    return true;
+}
 
-    autoArgs.sort(); // !!! inefficient
 
-    return true;
+void evalAutoArgs(EvalState & state, std::map<string, string> & in, Bindings & out)
+{
+    for (auto & i: in) {
+        Value * v = state.allocValue();
+        if (i.second[0] == 'E')
+            state.mkThunk_(*v, state.parseExprFromString(string(i.second, 1), absPath(".")));
+        else
+            mkString(*v, string(i.second, 1));
+        out.push_back(Attr(state.symbols.create(i.first), v));
+    }
+    out.sort();
 }
 
 
-bool parseSearchPathArg(const string & arg, Strings::iterator & i,
+bool parseSearchPathArg(Strings::iterator & i,
     const Strings::iterator & argsEnd, Strings & searchPath)
 {
-    if (arg != "-I") return false;
-    if (i == argsEnd) throw UsageError(format("`%1%' requires an argument") % arg);;
-    searchPath.push_back(*i++);
+    if (*i != "-I") return false;
+    if (++i == argsEnd) throw UsageError("`-I' requires an argument");
+    searchPath.push_back(*i);
     return true;
 }