X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/d620665f6b2e1ae5db4c98a09e35bd63133ae87f..ce17f0a9b30a6a1b9eaf1b97ddbfc43355e5355a:/src/main.rs?ds=inline diff --git a/src/main.rs b/src/main.rs index cb258c2..a5c2cf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,27 +1,64 @@ // mod argument_parser; mod configuration; mod command; +mod constants; +mod gemini_parser; +mod generator; +mod archiver; +mod metadata; +mod post; +mod template; +mod utils; +mod remote; +use std::iter::once; use std::env::args; use std::io::Result; -use configuration::Configuration; use command::{available_commands, Command, help::Help}; +use configuration::Configuration; fn main() -> Result<()> { - let configuration = Configuration::new(); - let commands = available_commands(); + let result = run(); - println!("CONFIGURATION DIRECTORY: {}", configuration.config_directory.display()); - println!("DATA DIRECTORY: {}", configuration.data_directory.display()); - println!("OUTPUT DIRECTORY: {}", configuration.output_directory.display()); + if cfg!(debug_assertions) { + result + } else { + match result { + Ok(_) => Ok(()), + Err(e) => { + eprintln!("Error: {}", e); + std::process::exit(1); + } + } + } +} +fn run() -> Result<()> { + let configuration = Configuration::new(); + let commands = available_commands(); let arguments: Vec = args().collect(); if let Some(command_name) = arguments.get(1) { - if let Some(command) = commands.iter().find(|&c| c.command() == command_name) { - return command.execute(arguments.get(2)); + if let Some(main_command) = commands.into_iter().find(|c| c.command() == command_name) { + let before_commands = main_command.before_dependencies(); + let after_commands = main_command.after_dependencies(); + + let command_chain: Vec> = before_commands + .into_iter() + .chain(once(main_command)) + .chain(after_commands.into_iter()) + .collect(); + + for command in command_chain { + let result = command.execute(arguments.get(2), &configuration, command_name); + if let Err(_) = result { + return result; + } + } + + return Ok(()) } } - Help::new().execute(None) + Help::new().execute(None, &configuration, &"help".to_string()) }