|
| 1 | +extern crate getopts; |
| 2 | +use getopts::Options; |
| 3 | +use std::env; |
| 4 | + |
| 5 | +mod runtime; |
| 6 | +mod cgroup; |
| 7 | +mod filesystem; |
| 8 | +mod mount; |
| 9 | +mod namespace; |
| 10 | + |
| 11 | +fn run(rootfs: Option<String>, command_string: Option<String>){ |
| 12 | + let rootfs = rootfs.unwrap(); |
| 13 | + let command_string = command_string.unwrap(); |
| 14 | + |
| 15 | + let child_command_buffer = command_string.split(" "); |
| 16 | + let mut child_command_vector = child_command_buffer.collect::<Vec<&str>>(); |
| 17 | + let command = child_command_vector[0]; |
| 18 | + child_command_vector.drain(0..1); |
| 19 | + |
| 20 | + runtime::run_container(&rootfs, command, child_command_vector); |
| 21 | +} |
| 22 | + |
| 23 | +fn print_usage(program: &str, opts: Options) { |
| 24 | + let brief = format!("Usage: {} vas-quod [options]", program); |
| 25 | + print!("{}", opts.usage(&brief)); |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +fn main() { |
| 30 | + let args: Vec<String> = env::args().collect(); |
| 31 | + let program = args[0].clone(); |
| 32 | + |
| 33 | + let mut opts = Options::new(); |
| 34 | + opts.optopt("r", "rootfs", "Path to root file-system eg. --rootfs /home/alpinefs", "path"); |
| 35 | + opts.optopt("c", "command", "Command to be executed eg. --command `curl http://google.com`", "command"); |
| 36 | + opts.optflag("h", "help", "print this help menu"); |
| 37 | + let matches = match opts.parse(&args[1..]) { |
| 38 | + Ok(m) => { m } |
| 39 | + Err(_f) => { |
| 40 | + println!("Error: Unrecognzied Options"); |
| 41 | + print_usage(&program, opts); |
| 42 | + return |
| 43 | + } |
| 44 | + }; |
| 45 | + if matches.opt_present("h") || !matches.opt_present("r") || !matches.opt_present("c") { |
| 46 | + print_usage(&program, opts); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + let rootfs = matches.opt_str("r"); |
| 51 | + let command_string = matches.opt_str("c"); |
| 52 | + run(rootfs, command_string); |
| 53 | +} |
0 commit comments