about summary refs log tree commit diff
path: root/users/Profpatsch/execline/exec_helpers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/execline/exec_helpers.rs')
-rw-r--r--users/Profpatsch/execline/exec_helpers.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/users/Profpatsch/execline/exec_helpers.rs b/users/Profpatsch/execline/exec_helpers.rs
index bc4650fbad9a..b9e1f5797386 100644
--- a/users/Profpatsch/execline/exec_helpers.rs
+++ b/users/Profpatsch/execline/exec_helpers.rs
@@ -11,6 +11,16 @@ pub fn no_args(current_prog_name: &str) -> () {
     }
 }
 
+pub fn args(current_prog_name: &str, no_of_positional_args: usize) -> Vec<Vec<u8>> {
+    let mut args = std::env::args_os();
+    // remove argv[0]
+    let _ = args.nth(0);
+    if args.len() != no_of_positional_args {
+        die_user_error(current_prog_name, format!("Expected {} arguments, got {}, namely {:?}", no_of_positional_args, args.len(), args.collect::<Vec<_>>()))
+    }
+    args.map(|arg| arg.into_vec()).collect()
+}
+
 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]