2021-01-29 15:39:33 +01:00
|
|
|
{ depot, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
netencode = {
|
2022-01-30 17:06:58 +01:00
|
|
|
rust = depot.nix.writers.rustSimpleLib
|
|
|
|
{
|
|
|
|
name = "arglib-netencode";
|
|
|
|
dependencies = [
|
|
|
|
depot.users.Profpatsch.execline.exec-helpers
|
|
|
|
depot.users.Profpatsch.netencode.netencode-rs
|
|
|
|
];
|
|
|
|
} ''
|
2021-01-29 15:39:33 +01:00
|
|
|
extern crate netencode;
|
2021-02-08 03:23:53 +01:00
|
|
|
extern crate exec_helpers;
|
2021-01-29 15:39:33 +01:00
|
|
|
|
|
|
|
use netencode::{T};
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
2021-02-08 03:23:53 +01:00
|
|
|
pub fn arglib_netencode(prog_name: &str, env: Option<&std::ffi::OsStr>) -> T {
|
2021-01-29 15:39:33 +01:00
|
|
|
let env = match env {
|
|
|
|
None => std::ffi::OsStr::from_bytes("ARGLIB_NETENCODE".as_bytes()),
|
|
|
|
Some(a) => a
|
|
|
|
};
|
2021-02-09 20:55:35 +01:00
|
|
|
let t = match std::env::var_os(env) {
|
2021-02-08 03:23:53 +01:00
|
|
|
None => exec_helpers::die_user_error(prog_name, format!("could not read args, envvar {} not set", env.to_string_lossy())),
|
2021-01-29 15:39:33 +01:00
|
|
|
// TODO: good error handling for the different parser errors
|
|
|
|
Some(soup) => match netencode::parse::t_t(soup.as_bytes()) {
|
|
|
|
Ok((remainder, t)) => match remainder.is_empty() {
|
2021-02-08 03:23:53 +01:00
|
|
|
true => t,
|
|
|
|
false => exec_helpers::die_environment_problem(prog_name, format!("arglib: there was some unparsed bytes remaining: {:?}", remainder))
|
2021-01-29 15:39:33 +01:00
|
|
|
},
|
2021-02-08 03:23:53 +01:00
|
|
|
Err(err) => exec_helpers::die_environment_problem(prog_name, format!("arglib parsing error: {:?}", err))
|
2021-01-29 15:39:33 +01:00
|
|
|
}
|
2021-02-09 20:55:35 +01:00
|
|
|
};
|
|
|
|
std::env::remove_var(env);
|
|
|
|
t
|
2021-01-29 15:39:33 +01:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
in
|
|
|
|
depot.nix.readTree.drvTargets netencode
|