aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-31 20:10:56 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-31 20:10:56 +0200
commit9169046e64cbffd85a445ebe4313b172a6681646 (patch)
treebca847de801368e8de25c65b5ca5220c0111e65e
parentb971e406dee82486d53737a928b0bb3b482a6c49 (diff)
Add operator << for LockFile
Useful for debugging.
-rw-r--r--src/libexpr/primops/flake.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index fdbdc83bc..af7d51834 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -121,7 +121,7 @@ nlohmann::json flakeEntryToJson(const LockFile::FlakeEntry & entry)
return json;
}
-void writeLockFile(const LockFile & lockFile, const Path & path)
+std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile)
{
nlohmann::json json;
json["version"] = 1;
@@ -133,8 +133,14 @@ void writeLockFile(const LockFile & lockFile, const Path & path)
json["inputs"] = nlohmann::json::object();
for (auto & x : lockFile.flakeEntries)
json["inputs"][x.first.to_string()] = flakeEntryToJson(x.second);
+ stream << json.dump(4); // '4' = indentation in json file
+ return stream;
+}
+
+void writeLockFile(const LockFile & lockFile, const Path & path)
+{
createDirs(dirOf(path));
- writeFile(path, json.dump(4) + "\n"); // '4' = indentation in json file
+ writeFile(path, fmt("%s\n", lockFile));
}
Path getUserRegistryPath()