Output messages

This commit is contained in:
southerntofu 2020-11-28 11:50:56 +01:00
parent b28c97fdb1
commit d7cded3297
4 changed files with 25 additions and 16 deletions

View File

@ -19,8 +19,8 @@ pub struct Cli {
}
impl Cli {
// Returns a PathBuf to the basedir. If it's a relative link,
// it's not expanded here! Panics if no basedir is provided and $HOME isn't defined
/// Returns a PathBuf to the basedir. If it's a relative link,
/// it's not expanded here! Panics if no basedir is provided and $HOME isn't defined
pub fn basedir(&self) -> PathBuf {
if let Some(basedir) = &self.basedir {
// Returns an error when the path doesn't exist

View File

@ -63,14 +63,14 @@ impl Repo {
pub fn clone(&self) -> bool {
match &self.backend {
Backend::Git => {
let status = Command::new("git")
let output = Command::new("git")
.arg("clone")
.arg("--recursive")
.arg(&self.source)
.arg(&self.dest)
.status()
.output() // To suppress (capture) output
.expect("PROCESS ERROR!");
status.success()
output.status.success()
}
Backend::Mercurial => {
unreachable!("Unimplemented");

View File

@ -10,6 +10,8 @@ mod log;
mod task;
fn main() -> Result<(), std::io::Error> {
// TODO: use StructOpt::from_iter_safe so we can hook on Cli error
// to display additional unknown_arg error message.
let cmd = cli::Cli::from_args();
let mut context = HashMap::new();
@ -18,7 +20,7 @@ fn main() -> Result<(), std::io::Error> {
let basedir = match basedir.canonicalize() {
Ok(p) => p,
Err(_) => {
context.insert("i18n_basedir", basedir.to_str().unwrap());
context.insert("$i18n_basedir", basedir.to_str().unwrap());
log::error("missing_basedir", Some(&context));
std::process::exit(1);
}
@ -29,12 +31,13 @@ fn main() -> Result<(), std::io::Error> {
set_var("GITBUILDDIR", &basedir);
let mut tasks = if cmd.tasks.is_empty() {
log::info("no_task", Some(&context));
task::from_dir(&basedir).expect("Could not load DB")
} else {
match task::from_dir_and_list(&basedir, cmd.tasks) {
Ok(t) => t,
Err(task::MissingTask(t)) => {
context.insert("i18n_task", &t);
context.insert("$i18n_task", &t);
log::error("unknown_arg", Some(&context));
std::process::exit(1);
}
@ -43,8 +46,9 @@ fn main() -> Result<(), std::io::Error> {
};
let (config_folder, ignored_tasks) = task::config(&basedir);
set_var("GITBUILDCONF", &config_folder);
context.insert("$i18n_config", config_folder.to_str().unwrap());
log::info("config", Some(&context));
// Reorder tasks alphanumerically
tasks.sort_unstable_by_key(|t| t.name.clone());
@ -52,14 +56,17 @@ fn main() -> Result<(), std::io::Error> {
// the corresponding source URL (so we'd be tempted to call the task twice)
tasks.dedup_by_key(|t| t.name.clone());
for task in &tasks {
let mut context = context.clone();
context.insert("$i18n_task", task.name.as_str());
log::debug("found_task", Some(&context));
if ignored_tasks.contains(&task.name) {
// Skip task which has CONFIG/task.ignore
continue;
}
let mut context = context.clone();
context.insert("$i18n_task", task.name.as_str());
log::debug("found_task", Some(&context));
log::info("process", Some(&context));
// Maybe the task has a source we should clone?
if let Some(repo) = &task.repo {
context.insert("$source", &repo.source);
@ -74,7 +81,6 @@ fn main() -> Result<(), std::io::Error> {
}
// New repo just cloned
// TODO: submodule and submodule updates
println!("Downloaded source for {}", task.name);
cd(&source_dir).expect("Failed to change working dir");
// Checkout specific branch?
@ -83,7 +89,7 @@ fn main() -> Result<(), std::io::Error> {
} else {
// So the cloned repo is already here maybe update?
// Let's say there was an update and run
println!("Task {} already exists, run i t only if updates", task.name);
//println!("Task {} already exists, run i t only if updates", task.name);
cd(&source_dir).expect("Failed to change working dir");
task.checkout();
task.update_and_run(&cmd.force);
@ -92,7 +98,7 @@ fn main() -> Result<(), std::io::Error> {
} else {
// No source, chaneg working dir to basedir
cd(&basedir).expect("Failed to change working dir");
println!("Taks {} doesn't have a source, run it", task.name);
//println!("Taks {} doesn't have a source, run it", task.name);
task.run_once();
}
}

View File

@ -96,7 +96,6 @@ impl Task {
}
pub fn run_on_host(&self) -> bool {
println!("{:#?}", self.hosts);
if self.hosts.len() == 0 {
return true;
}
@ -104,7 +103,6 @@ impl Task {
// to find out the actual hostname
let hostname = std::env::var("HOST")
.unwrap_or_else(|_| hostname::get().unwrap().into_string().unwrap());
println!("HOSTNAME: {}", hostname);
if self.hosts.contains(&hostname) {
return true;
}
@ -131,9 +129,14 @@ impl Task {
pub fn run(&self) {
if !self.run_on_host() {
// TODO: Skip host debug?
return;
}
let mut context = HashMap::new();
context.insert("$i18n_task", self.name.as_str());
log::info("run", Some(&context));
let cmd_out = Command::new("bash") // TODO: no need to call bash?
.arg(&self.bin)
.arg(&self.name)