feat(users/Profpatsch/execline): add args_for_exec

`exec_into_args` would just read argv and exec into it, but we want to
be able to write commands which take some positional arguments first.

Thus we split the invocation into `args_for_exec`, which returns the
positional arguments and prog, and then pass prog to `exec_into_args`
when we want to exec eventually (prog is still an iterator at this
point).

Change-Id: I0b180c1a100b96363fe33ba2c42034ed41716b7a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2474
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2021-01-31 15:47:49 +01:00
parent f0579313d3
commit 83634341aa
3 changed files with 50 additions and 25 deletions

View file

@ -99,17 +99,16 @@ let
extern crate netencode;
extern crate exec_helpers;
use netencode::dec::{Record, ScalarAsBytes, Decoder, DecodeError};
fn main() {
let t = netencode::t_from_stdin_or_panic("record-splice-env");
match Record::<ScalarAsBytes>::dec(t) {
Ok(map) => {
exec_helpers::exec_into_args(
"record-splice-env",
map.iter().map(|(k,v)| (k.as_bytes(), &v[..])
);
},
Err(DecodeError(err)) => panic!("{}", err),
}
let (_, prog) = exec_helpers::args_for_exec("record-splice-env", 0);
match Record::<ScalarAsBytes>::dec(t) {
Ok(map) => {
exec_helpers::exec_into_args("record-splice-env", prog, map);
},
Err(DecodeError(err)) => panic!("{}", err),
}
}
'';