Skip to content

Commit

Permalink
Alow taking directory and placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Aug 14, 2019
1 parent 0f45400 commit 0ae980c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main.rs
Expand Up @@ -68,8 +68,16 @@ fn parse_msg(msg: &str) -> Option<Msg> {

fn main() -> Result<(), std::io::Error> {
let args: Vec<String> = std::env::args().collect();
let program = &args[1];
let subdirectories = fs::read_dir(".")?;
let program = if let Some(program) = args.get(1) {
program
} else {
panic!("Usage: {} <program> [root_dir]");
};

let default_root_dir = ".".to_string();
let root_dir = args.get(2).unwrap_or(&default_root_dir);

let subdirectories = fs::read_dir(root_dir)?;

let mut processes = std::collections::HashMap::new();

Expand All @@ -80,8 +88,9 @@ fn main() -> Result<(), std::io::Error> {
println!("Ignoring non-directory: {:?}", path);
continue;
}
let sub_name = path.file_name().unwrap().to_str().unwrap();
let mut process = Subprocess::new(path.to_str().unwrap().to_string())?;
process.start(&program)?;
process.start(&program.replace("{}", sub_name))?;
if let Some(name) = path.file_name() {
processes.insert(name.to_str().unwrap().to_string(), process);
}
Expand Down

0 comments on commit 0ae980c

Please sign in to comment.