diff options
| author | bnewbold <bnewbold@robocracy.org> | 2016-09-27 01:16:25 -0700 | 
|---|---|---|
| committer | bnewbold <bnewbold@robocracy.org> | 2016-09-27 01:16:25 -0700 | 
| commit | 1febaf12b62603d0224468023d8a78169c2d2b0d (patch) | |
| tree | b3badf7aae130ae90eebfe25c195e303b6377f42 | |
| parent | 263a1df7a5737f37916e653e85ccff2852276fc3 (diff) | |
| download | einhyrningsins-1febaf12b62603d0224468023d8a78169c2d2b0d.tar.gz einhyrningsins-1febaf12b62603d0224468023d8a78169c2d2b0d.zip | |
more skeleton code
| -rw-r--r-- | Cargo.lock | 42 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 41 | 
3 files changed, 36 insertions, 48 deletions
| @@ -5,7 +5,6 @@ dependencies = [   "env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",   "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",   "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",  ]  [[package]] @@ -17,16 +16,6 @@ dependencies = [  ]  [[package]] -name = "bitflags" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cfg-if" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]]  name = "env_logger"  version = "0.3.5"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -68,19 +57,6 @@ dependencies = [  ]  [[package]] -name = "nix" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]]  name = "regex"  version = "0.1.77"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -98,19 +74,6 @@ version = "0.3.5"  source = "registry+https://github.com/rust-lang/crates.io-index"  [[package]] -name = "rustc_version" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]]  name = "thread-id"  version = "2.0.0"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -133,11 +96,6 @@ version = "0.1.3"  source = "registry+https://github.com/rust-lang/crates.io-index"  [[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]]  name = "winapi"  version = "0.2.8"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -4,7 +4,6 @@ version = "0.1.0"  authors = ["bnewbold <bnewbold@robocracy.org>"]  [dependencies] -nix = "0.7.0"  log = "0.3"  env_logger = "0.3"  getopts = "^0.2" diff --git a/src/main.rs b/src/main.rs index d0f6bc6..d87f037 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,30 +17,47 @@   */  extern crate getopts; -extern crate nix;  extern crate log;  extern crate env_logger;  use std::env; +use std::u64; +use std::str::FromStr; +use std::{time, thread};  use std::process::exit; +use std::process::Command;  use getopts::Options; +fn run(prog: Vec<String>, number: u64) { + + +    for _ in 0..number { +        println!("Running!"); +        Command::new(&prog[0]) +                .args(&prog[1..]) +                .spawn() +                .expect("command failed"); +    } + +    println!("Sleeping for 1sec"); +    thread::sleep(time::Duration::from_secs(1)); +} +  fn print_usage(opts: Options) { -    let brief = "usage:\teinhyrningsins [options] program"; // XXX: +    let brief = "usage:\teinhyrningsins [options] program";      println!("");      print!("{}", opts.usage(&brief));  }  fn main() { -    println!("Hello, world!");      let args: Vec<String> = env::args().collect();      let mut opts = Options::new();      opts.optflag("h", "help", "print this help menu");      opts.optflag("v", "verbose", "more debugging messages"); -    opts.optflag("n", "number", "how many program copies to spawn"); -    opts.optflag("b", "bind", "how many program copies to spawn"); +    opts.optopt("n", "number", "how many program copies to spawn", "COUNT"); +    opts.optmulti("b", "bind", "socket(s) to bind to", "ADDR");      let matches = match opts.parse(&args[1..]) {          Ok(m) => { m } @@ -52,10 +69,24 @@ fn main() {          return;      } +    let number: u64 = match matches.opt_str("number") { +        Some(n) => u64::from_str(&n).unwrap(), +        None => 1 +    }; + +    let program_and_args = if !matches.free.is_empty() { +        matches.free +    } else { +        print_usage(opts); +        exit(-1); +    }; +      let mut builder = env_logger::LogBuilder::new();      builder.parse("INFO");      if env::var("RUST_LOG").is_ok() {          builder.parse(&env::var("RUST_LOG").unwrap());      }      builder.init().unwrap(); + +    run(program_and_args, number);  } | 
