feat(users/Profpatsch/execline/exec_helpers): add no_args()

Some programs don’t need any arguments, so fail if they do get them,
because that’s usually a bug.

Change-Id: I28639056d3d9cea0cc0e7fcbfa42120c4f129c8c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2503
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2021-02-09 21:06:07 +01:00
parent 1e5baa0dea
commit 060600f0d7
2 changed files with 11 additions and 0 deletions

View file

@ -2,6 +2,15 @@ use std::os::unix::process::CommandExt;
use std::ffi::OsStr;
use std::os::unix::ffi::{OsStringExt, OsStrExt};
pub fn no_args(current_prog_name: &str) -> () {
let mut args = std::env::args_os();
// remove argv[0]
let _ = args.nth(0);
if args.len() > 0 {
die_user_error(current_prog_name, format!("Expected no arguments, got {:?}", args.collect::<Vec<_>>()))
}
}
pub fn args_for_exec(current_prog_name: &str, no_of_positional_args: usize) -> (Vec<Vec<u8>>, Vec<Vec<u8>>) {
let mut args = std::env::args_os();
// remove argv[0]