Support variant config parsing on CLI
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 28 Mar 2022 18:52:08 +0000 (20:52 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Wed, 30 Mar 2022 18:03:29 +0000 (20:03 +0200)
Use here-docs to load variant configurations from the CLI.

```
load <<EOF
[testvariant:chess]
somerule = somevalue
EOF
```

src/uci.cpp

index 94176a5..2992100 100644 (file)
@@ -249,9 +249,29 @@ namespace {
 
     string token;
     std::getline(is >> std::ws, token);
-    std::size_t end = token.find_last_not_of(' ');
-    if (end != std::string::npos)
-        Options["VariantPath"] = token.erase(end + 1);
+
+    // The argument to load either is a here-doc or a file path
+    if (token.rfind("<<", 0) == 0)
+    {
+        // Trim the EOF marker
+        if (!(stringstream(token.substr(2)) >> token))
+            token = "";
+
+        // Parse variant config till EOF marker
+        stringstream ss;
+        std::string line;
+        while (std::getline(cin, line) && line != token)
+            ss << line << std::endl;
+        variants.parse_istream<false>(ss);
+        Options["UCI_Variant"].set_combo(variants.get_keys());
+    }
+    else
+    {
+        // store path if non-empty after trimming
+        std::size_t end = token.find_last_not_of(' ');
+        if (end != std::string::npos)
+            Options["VariantPath"] = token.erase(end + 1);
+    }
   }
 
   // check() is called when engine receives the "check" command.