about summary refs log tree commit diff
path: root/users/Profpatsch/netencode/default.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-02-14T15·53+0100
committerProfpatsch <mail@profpatsch.de>2021-04-23T20·45+0000
commit5ca71308a8f1ab61a3991991dd27bbb373a0d25f (patch)
tree49e162af9ccb417561c6e22ab4b82d7871bf0086 /users/Profpatsch/netencode/default.nix
parent9d7c3ee877837070c51760cb621bc409c6d0f6a7 (diff)
feat(users/Profpatsch/netencode): add pretty printer r/2544
Simple pretty printer for netencode values, as a rust library and an
accompanying command line tool which takes netencode on stdin and
prints the pretty version to stdout.

Change-Id: I0a57c644985162bc08a9bf1ee78f7be278400199
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2532
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/netencode/default.nix')
-rw-r--r--users/Profpatsch/netencode/default.nix32
1 files changed, 32 insertions, 0 deletions
diff --git a/users/Profpatsch/netencode/default.nix b/users/Profpatsch/netencode/default.nix
index 3088ee66bfe4..843408941d82 100644
--- a/users/Profpatsch/netencode/default.nix
+++ b/users/Profpatsch/netencode/default.nix
@@ -18,6 +18,36 @@ let
 
   gen = import ./gen.nix { inherit lib; };
 
+  pretty-rs = imports.writers.rustSimpleLib {
+    name = "netencode-pretty";
+    dependencies = [
+      netencode-rs
+    ];
+  } (builtins.readFile ./pretty.rs);
+
+  pretty = depot.users.Profpatsch.writers.rustSimple {
+    name = "netencode-pretty";
+    dependencies = [
+      netencode-rs
+      pretty-rs
+      depot.users.Profpatsch.execline.exec-helpers
+    ];
+  } ''
+    extern crate netencode;
+    extern crate netencode_pretty;
+    extern crate exec_helpers;
+
+    fn main() {
+      let (_, prog) = exec_helpers::args_for_exec("eprint-stdin-netencode", 0);
+      let mut buf = vec![];
+      let u = netencode::u_from_stdin_or_die_user_error("eprint-stdin-netencode", &mut buf);
+      match netencode_pretty::Pretty::from_u(u).print_multiline(&mut std::io::stdout()) {
+        Ok(()) => {},
+        Err(err) => exec_helpers::die_temporary("eprint-stdin-netencode", format!("could not write to stdout: {}", err))
+      }
+    }
+  '';
+
   netencode-mustache = imports.writers.rustSimple {
     name = "netencode_mustache";
     dependencies = [
@@ -115,6 +145,8 @@ let
 in depot.nix.utils.drvTargets {
   inherit
     netencode-rs
+    pretty-rs
+    pretty
     netencode-mustache
     record-get
     record-splice-env