Commit 9a845921 authored by AdminXVII's avatar AdminXVII

Move in functions

parent 3b48cdda
......@@ -75,6 +75,45 @@ struct JobResult {
cmd: String,
}
fn add_jobs(
command: Arc<String>,
arguments: Vec<String>,
argfile: Option<PathBuf>,
tx: Sender<String>,
) {
let mut i = 0;
for argument in arguments {
debug!("Starting {}: '{}'", i, command.replace("{}", &argument));
tx.send(argument).unwrap();
i += 1;
}
if let Some(argfile) = argfile {
let file = match File::open(&argfile) {
Err(err) => {
error!(
"Could not open arg file '{}' for reading: {}",
argfile.to_string_lossy(),
err
);
std::process::exit(1);
}
Ok(file) => file,
};
for arg in BufReader::new(file).lines() {
let arg = arg.expect("Could not read the file");
debug!("Starting {}: '{}'", i, command.replace("{}", &arg));
tx.send(arg.to_string()).unwrap();
i += 1;
}
}
for arg in BufReader::new(io::stdin().lock()).lines() {
let arg = arg.expect("Could not read the file");
debug!("Starting {}: '{}'", i, command.replace("{}", &arg));
tx.send(arg.to_string()).unwrap();
i += 1;
}
}
fn create_logger(opts: &Opts) {
let level = match (opts.quiet, opts.verbose) {
(true, _) => LevelFilter::Error,
......@@ -161,38 +200,7 @@ fn main() {
rtx,
);
let mut i = 0;
for argument in opts.arguments {
debug!("Starting {}: '{}'", i, command.replace("{}", &argument));
tx.send(argument).unwrap();
i += 1;
}
if let Some(argfile) = opts.argfile {
let file = match File::open(&argfile) {
Err(err) => {
error!(
"Could not open arg file '{}' for reading: {}",
argfile.to_string_lossy(),
err
);
std::process::exit(1);
}
Ok(file) => file,
};
for arg in BufReader::new(file).lines() {
let arg = arg.expect("Could not read the file");
debug!("Starting {}: '{}'", i, command.replace("{}", &arg));
tx.send(arg.to_string()).unwrap();
i += 1;
}
}
for arg in BufReader::new(io::stdin().lock()).lines() {
let arg = arg.expect("Could not read the file");
debug!("Starting {}: '{}'", i, command.replace("{}", &arg));
tx.send(arg.to_string()).unwrap();
i += 1;
}
std::mem::drop(tx);
add_jobs(command, opts.arguments, opts.argfile, tx);
let mut exit = 0;
while let Ok(result) = rrx.recv() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment