feat(users/Profpatsch/netencode): add record-get
Projecting into one record field of netencode given on stdin. Change-Id: I975bd5558a06988aa159156ca73a449710db983f Reviewed-on: https://cl.tvl.fyi/c/depot/+/2502 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
parent
7a4aca42ad
commit
1e5baa0dea
1 changed files with 30 additions and 0 deletions
|
@ -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
|
||||
;
|
||||
|
|
Loading…
Reference in a new issue