From 5e8c00d819bddd00637094e770b62d2e30bfe4a7 Mon Sep 17 00:00:00 2001 From: quirinecker Date: Tue, 24 Jan 2023 01:55:49 +0100 Subject: [PATCH] changed order of blocks and removed commented code --- src/app/commands/build.rs | 85 ++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/src/app/commands/build.rs b/src/app/commands/build.rs index b7ce21e..68d9f5e 100644 --- a/src/app/commands/build.rs +++ b/src/app/commands/build.rs @@ -8,6 +8,45 @@ pub struct Build { builder: Box, } +impl Command for Build { + fn execute(&self, _args: &HashMap) -> Result<(), String> { + let path = format!("./docs/"); + let mut error_count = 0; + + if !self.docs_directory_exists(&path) { + error_count += 1; + println!( + "docs directory does not exist. Either create it or clone the template from gitlab" + ) + } else { + for result in self.build_dir(&path) { + match result { + Err(e) => { + error_count += 1; + println!("{e}"); + } + Ok(()) => println!("success"), + }; + } + } + + if error_count > 0 { + return Err(format!("failed with {} errors", error_count)); + } + + return Ok(()); + } + + fn new() -> Self + where + Self: Sized, + { + return Build { + builder: Box::new(AsciiDoctorBuilder {}), + }; + } +} + impl Build { fn build_dir(&self, path: &str) -> Vec> { let mut results = vec![]; @@ -51,49 +90,3 @@ impl Build { } } -impl Command for Build { - fn execute(&self, _args: &HashMap) -> Result<(), String> { - // let Ok(project_cwd_object) = env::current_dir() else { - // return Err("current dirctory does not seem to exist".to_string()) - // }; - // - // let Some(project_cwd) = project_cwd_object.to_str() else { - // return Err("invalid path".to_string()); - // }; - - let path = format!("./docs/"); - let mut error_count = 0; - - if !self.docs_directory_exists(&path) { - error_count += 1; - println!( - "docs directory does not exist. Either create it or clone the template from gitlab" - ) - } else { - for result in self.build_dir(&path) { - match result { - Err(e) => { - error_count += 1; - println!("{e}"); - } - Ok(()) => println!("success"), - }; - } - } - - if error_count > 0 { - return Err(format!("failed with {} errors", error_count)); - } - - return Ok(()); - } - - fn new() -> Self - where - Self: Sized, - { - return Build { - builder: Box::new(AsciiDoctorBuilder {}), - }; - } -}