Output messages
This commit is contained in:
parent
b28c97fdb1
commit
d7cded3297
|
@ -19,8 +19,8 @@ pub struct Cli {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl Cli {
|
||||||
// Returns a PathBuf to the basedir. If it's a relative link,
|
/// 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
|
/// it's not expanded here! Panics if no basedir is provided and $HOME isn't defined
|
||||||
pub fn basedir(&self) -> PathBuf {
|
pub fn basedir(&self) -> PathBuf {
|
||||||
if let Some(basedir) = &self.basedir {
|
if let Some(basedir) = &self.basedir {
|
||||||
// Returns an error when the path doesn't exist
|
// Returns an error when the path doesn't exist
|
||||||
|
|
|
@ -63,14 +63,14 @@ impl Repo {
|
||||||
pub fn clone(&self) -> bool {
|
pub fn clone(&self) -> bool {
|
||||||
match &self.backend {
|
match &self.backend {
|
||||||
Backend::Git => {
|
Backend::Git => {
|
||||||
let status = Command::new("git")
|
let output = Command::new("git")
|
||||||
.arg("clone")
|
.arg("clone")
|
||||||
.arg("--recursive")
|
.arg("--recursive")
|
||||||
.arg(&self.source)
|
.arg(&self.source)
|
||||||
.arg(&self.dest)
|
.arg(&self.dest)
|
||||||
.status()
|
.output() // To suppress (capture) output
|
||||||
.expect("PROCESS ERROR!");
|
.expect("PROCESS ERROR!");
|
||||||
status.success()
|
output.status.success()
|
||||||
}
|
}
|
||||||
Backend::Mercurial => {
|
Backend::Mercurial => {
|
||||||
unreachable!("Unimplemented");
|
unreachable!("Unimplemented");
|
||||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -10,6 +10,8 @@ mod log;
|
||||||
mod task;
|
mod task;
|
||||||
|
|
||||||
fn main() -> Result<(), std::io::Error> {
|
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 cmd = cli::Cli::from_args();
|
||||||
|
|
||||||
let mut context = HashMap::new();
|
let mut context = HashMap::new();
|
||||||
|
@ -18,7 +20,7 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
let basedir = match basedir.canonicalize() {
|
let basedir = match basedir.canonicalize() {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
context.insert("i18n_basedir", basedir.to_str().unwrap());
|
context.insert("$i18n_basedir", basedir.to_str().unwrap());
|
||||||
log::error("missing_basedir", Some(&context));
|
log::error("missing_basedir", Some(&context));
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
@ -29,12 +31,13 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
set_var("GITBUILDDIR", &basedir);
|
set_var("GITBUILDDIR", &basedir);
|
||||||
|
|
||||||
let mut tasks = if cmd.tasks.is_empty() {
|
let mut tasks = if cmd.tasks.is_empty() {
|
||||||
|
log::info("no_task", Some(&context));
|
||||||
task::from_dir(&basedir).expect("Could not load DB")
|
task::from_dir(&basedir).expect("Could not load DB")
|
||||||
} else {
|
} else {
|
||||||
match task::from_dir_and_list(&basedir, cmd.tasks) {
|
match task::from_dir_and_list(&basedir, cmd.tasks) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(task::MissingTask(t)) => {
|
Err(task::MissingTask(t)) => {
|
||||||
context.insert("i18n_task", &t);
|
context.insert("$i18n_task", &t);
|
||||||
log::error("unknown_arg", Some(&context));
|
log::error("unknown_arg", Some(&context));
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +46,9 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (config_folder, ignored_tasks) = task::config(&basedir);
|
let (config_folder, ignored_tasks) = task::config(&basedir);
|
||||||
|
|
||||||
set_var("GITBUILDCONF", &config_folder);
|
set_var("GITBUILDCONF", &config_folder);
|
||||||
|
context.insert("$i18n_config", config_folder.to_str().unwrap());
|
||||||
|
log::info("config", Some(&context));
|
||||||
|
|
||||||
// Reorder tasks alphanumerically
|
// Reorder tasks alphanumerically
|
||||||
tasks.sort_unstable_by_key(|t| t.name.clone());
|
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)
|
// the corresponding source URL (so we'd be tempted to call the task twice)
|
||||||
tasks.dedup_by_key(|t| t.name.clone());
|
tasks.dedup_by_key(|t| t.name.clone());
|
||||||
for task in &tasks {
|
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) {
|
if ignored_tasks.contains(&task.name) {
|
||||||
// Skip task which has CONFIG/task.ignore
|
// Skip task which has CONFIG/task.ignore
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut context = context.clone();
|
log::info("process", Some(&context));
|
||||||
context.insert("$i18n_task", task.name.as_str());
|
|
||||||
log::debug("found_task", Some(&context));
|
|
||||||
// Maybe the task has a source we should clone?
|
// Maybe the task has a source we should clone?
|
||||||
if let Some(repo) = &task.repo {
|
if let Some(repo) = &task.repo {
|
||||||
context.insert("$source", &repo.source);
|
context.insert("$source", &repo.source);
|
||||||
|
@ -74,7 +81,6 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
}
|
}
|
||||||
// New repo just cloned
|
// New repo just cloned
|
||||||
// TODO: submodule and submodule updates
|
// TODO: submodule and submodule updates
|
||||||
println!("Downloaded source for {}", task.name);
|
|
||||||
cd(&source_dir).expect("Failed to change working dir");
|
cd(&source_dir).expect("Failed to change working dir");
|
||||||
|
|
||||||
// Checkout specific branch?
|
// Checkout specific branch?
|
||||||
|
@ -83,7 +89,7 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
} else {
|
} else {
|
||||||
// So the cloned repo is already here maybe update?
|
// So the cloned repo is already here maybe update?
|
||||||
// Let's say there was an update and run
|
// 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");
|
cd(&source_dir).expect("Failed to change working dir");
|
||||||
task.checkout();
|
task.checkout();
|
||||||
task.update_and_run(&cmd.force);
|
task.update_and_run(&cmd.force);
|
||||||
|
@ -92,7 +98,7 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
} else {
|
} else {
|
||||||
// No source, chaneg working dir to basedir
|
// No source, chaneg working dir to basedir
|
||||||
cd(&basedir).expect("Failed to change working dir");
|
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();
|
task.run_once();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,6 @@ impl Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_on_host(&self) -> bool {
|
pub fn run_on_host(&self) -> bool {
|
||||||
println!("{:#?}", self.hosts);
|
|
||||||
if self.hosts.len() == 0 {
|
if self.hosts.len() == 0 {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +103,6 @@ impl Task {
|
||||||
// to find out the actual hostname
|
// to find out the actual hostname
|
||||||
let hostname = std::env::var("HOST")
|
let hostname = std::env::var("HOST")
|
||||||
.unwrap_or_else(|_| hostname::get().unwrap().into_string().unwrap());
|
.unwrap_or_else(|_| hostname::get().unwrap().into_string().unwrap());
|
||||||
println!("HOSTNAME: {}", hostname);
|
|
||||||
if self.hosts.contains(&hostname) {
|
if self.hosts.contains(&hostname) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -131,9 +129,14 @@ impl Task {
|
||||||
|
|
||||||
pub fn run(&self) {
|
pub fn run(&self) {
|
||||||
if !self.run_on_host() {
|
if !self.run_on_host() {
|
||||||
|
// TODO: Skip host debug?
|
||||||
return;
|
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?
|
let cmd_out = Command::new("bash") // TODO: no need to call bash?
|
||||||
.arg(&self.bin)
|
.arg(&self.bin)
|
||||||
.arg(&self.name)
|
.arg(&self.name)
|
||||||
|
|
Loading…
Reference in New Issue