about summary refs log tree commit diff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/Profpatsch/netencode/default.nix30
1 files changed, 30 insertions, 0 deletions
diff --git a/users/Profpatsch/netencode/default.nix b/users/Profpatsch/netencode/default.nix
index 3b62c8aaac59..92672470e902 100644
--- a/users/Profpatsch/netencode/default.nix
+++ b/users/Profpatsch/netencode/default.nix
@@ -93,6 +93,35 @@ let
   } (builtins.readFile ./netencode-mustache.rs);
 
 
+  record-get = imports.writers.rustSimple {
+    name = "record-get";
+    dependencies = [
+      netencode-rs
+      depot.users.Profpatsch.execline.exec-helpers
+      depot.users.Profpatsch.arglib.netencode.rust
+    ];
+  } ''
+    extern crate netencode;
+    extern crate arglib_netencode;
+    extern crate exec_helpers;
+    use netencode::{encode, dec};
+    use netencode::dec::{Decoder, DecodeError};
+
+    fn main() {
+        let mut buf = vec![];
+        let (args, prog) = exec_helpers::args_for_exec("record-get", 1);
+        let field = match std::str::from_utf8(&args[0]) {
+            Ok(f) => f,
+            Err(_e) => exec_helpers::die_user_error("record-get", format!("The field name needs to be valid unicode"))
+        };
+        let u = netencode::u_from_stdin_or_die_user_error("record-get", &mut buf);
+        match (dec::RecordDot {field, inner: dec::AnyU }).dec(u) {
+            Ok(u) => encode(&mut std::io::stdout(), &u).expect("encoding to stdout failed"),
+            Err(DecodeError(err)) => exec_helpers::die_user_error("record-get", err)
+        }
+    }
+  '';
+
   record-splice-env = imports.writers.rustSimple {
     name = "record-splice-env";
     dependencies = [
@@ -122,6 +151,7 @@ in {
    netencode-rs
    netencode-rs-tests
    netencode-mustache
+   record-get
    record-splice-env
    gen
    ;