From 1febaf12b62603d0224468023d8a78169c2d2b0d Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 27 Sep 2016 01:16:25 -0700 Subject: more skeleton code --- Cargo.lock | 42 ------------------------------------------ Cargo.toml | 1 - src/main.rs | 41 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a0e669..f9a0b2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] @@ -16,16 +15,6 @@ dependencies = [ "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[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" @@ -67,19 +56,6 @@ dependencies = [ "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[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" @@ -97,19 +73,6 @@ name = "regex-syntax" 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" @@ -132,11 +95,6 @@ name = "utf8-ranges" 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" diff --git a/Cargo.toml b/Cargo.toml index 2ed02ee..e8cd7e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors = ["bnewbold "] [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, 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 = 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); } -- cgit v1.2.3