build.rs/src/main.rs

53 lines
1.7 KiB
Rust
Raw Normal View History

2020-04-30 16:53:49 +00:00
use std::env;
use std::collections::HashMap;
2020-05-01 10:48:22 +00:00
use structopt::StructOpt;
2020-06-01 14:56:24 +00:00
// For UNIX extended metadata
2020-04-30 16:53:49 +00:00
mod log;
2020-04-30 20:11:06 +00:00
mod db;
2020-04-30 23:45:48 +00:00
mod dvcs;
2020-05-01 10:48:22 +00:00
mod cli;
2020-06-01 14:56:24 +00:00
mod task;
2020-04-30 16:53:49 +00:00
2020-06-01 14:56:24 +00:00
fn main() -> Result<(), std::io::Error> {
2020-05-01 10:48:22 +00:00
let cmd = cli::Cli::from_args();
let base_dir: String = cmd.basedir().to_str().unwrap().into();
2020-05-01 10:48:22 +00:00
2020-05-01 11:19:33 +00:00
let tasks = if cmd.tasks.is_empty() {
2020-06-10 11:04:35 +00:00
task::from_dir(&base_dir).expect("Could not load DB")
2020-05-01 11:19:33 +00:00
} else {
2020-06-10 11:04:35 +00:00
task::from_dir_and_list(&base_dir, cmd.tasks).expect("Could not load given tasks")
2020-05-01 11:19:33 +00:00
};
2020-06-10 11:04:35 +00:00
2020-06-01 14:56:24 +00:00
for (task_name, task) in tasks.iter() {
println!("TASK: {:?}", task_name);
2020-04-30 23:45:48 +00:00
let mut context = HashMap::new();
2020-06-01 14:56:24 +00:00
context.insert("$i18n_task", task_name.as_str());
2020-04-30 23:45:48 +00:00
log::debug("found_task", Some(&context));
// Maybe the task has a source we should clone?
if let Some(source) = &task.source {
if task.cloned == false {
2020-04-30 23:45:48 +00:00
if !task.dvcs.clone(source) {
context.insert("$i18n_source", &source);
log::error("clone_failed", Some(&context));
// Skip further processing
2020-05-01 10:48:22 +00:00
continue
2020-04-30 23:45:48 +00:00
}
2020-07-01 15:38:27 +00:00
// New repo just cloned
// TODO: submodule and submodule updates
println!("Downloaded source for {}", task_name);
task.run();
2020-04-30 23:45:48 +00:00
}
// So the cloned repo is already here maybe update?
// Let's say there was an update and run
println!("Task {} already exists, run it", task_name);
task.run();
} else {
println!("Taks {} doesn't have a source, run it", task_name);
task.run_once();
2020-04-30 23:45:48 +00:00
}
}
2020-06-01 14:56:24 +00:00
Ok(())
2020-04-30 16:53:49 +00:00
}