added two more descriptive error messages
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
use std::{collections::HashMap, env, fs};
|
use std::{collections::HashMap, env, fs, path::Path};
|
||||||
|
|
||||||
use crate::app::builder::{Builder, asciidoctor::AsciiDoctorBuilder};
|
use crate::app::builder::{asciidoctor::AsciiDoctorBuilder, Builder};
|
||||||
|
|
||||||
use super::traits::Command;
|
use super::traits::Command;
|
||||||
|
|
||||||
pub struct Build {
|
pub struct Build {
|
||||||
builder: Box<dyn Builder>
|
builder: Box<dyn Builder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Build {
|
impl Build {
|
||||||
fn build_dir(&self, path: &str) -> Vec<Result<(), String>> {
|
fn build_dir(&self, path: &str) -> Vec<Result<(), String>> {
|
||||||
let mut results = vec![];
|
let mut results = vec![];
|
||||||
let Ok(dirs) = fs::read_dir(path) else {
|
let Ok(dirs) = fs::read_dir(path) else {
|
||||||
return vec![Err("could not read file system".to_string())]
|
return vec![Err(format!("direcotry {path} was not found. The filesystem was maybe updated while build"))]
|
||||||
};
|
};
|
||||||
|
|
||||||
for result in dirs {
|
for result in dirs {
|
||||||
@@ -20,15 +20,15 @@ impl Build {
|
|||||||
return vec![Err("could not read entry".to_string())];
|
return vec![Err("could not read entry".to_string())];
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = entry.path().to_str()
|
let path = entry
|
||||||
|
.path()
|
||||||
|
.to_str()
|
||||||
.expect("could not get text path")
|
.expect("could not get text path")
|
||||||
.to_string()
|
.to_string()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
if entry.path().is_dir() {
|
if entry.path().is_dir() {
|
||||||
results = [
|
results = [results, self.build_dir(&path)].concat()
|
||||||
results, self.build_dir(&path)
|
|
||||||
].concat()
|
|
||||||
} else {
|
} else {
|
||||||
results.push(self.build_file(&path));
|
results.push(self.build_file(&path));
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,10 @@ impl Build {
|
|||||||
|
|
||||||
return self.builder.build(&path, &out_path);
|
return self.builder.build(&path, &out_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn docs_directory_exists(&self, path: &String) -> bool {
|
||||||
|
Path::new(path).is_dir()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command for Build {
|
impl Command for Build {
|
||||||
@@ -60,18 +64,25 @@ impl Command for Build {
|
|||||||
let path = format!("{project_cwd}/docs/");
|
let path = format!("{project_cwd}/docs/");
|
||||||
let mut error_count = 0;
|
let mut error_count = 0;
|
||||||
|
|
||||||
for result in self.build_dir(&path) {
|
if !self.docs_directory_exists(&path) {
|
||||||
match result {
|
error_count += 1;
|
||||||
Err(e) => {
|
println!(
|
||||||
error_count += 1;
|
"docs directory does not exist. Either create it or clone the template from gitlab"
|
||||||
println!("{e}");
|
)
|
||||||
},
|
} else {
|
||||||
Ok(()) => println!("success")
|
for result in self.build_dir(&path) {
|
||||||
};
|
match result {
|
||||||
|
Err(e) => {
|
||||||
|
error_count += 1;
|
||||||
|
println!("{e}");
|
||||||
|
}
|
||||||
|
Ok(()) => println!("success"),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if error_count > 0{
|
if error_count > 0 {
|
||||||
return Err(format!("failed with {} errors", error_count))
|
return Err(format!("failed with {} errors", error_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -82,7 +93,7 @@ impl Command for Build {
|
|||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
return Build {
|
return Build {
|
||||||
builder: Box::new(AsciiDoctorBuilder {})
|
builder: Box::new(AsciiDoctorBuilder {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user