]> git.r.bdr.sh - rbdr/blog/blob - src/main.rs
a0a9fefc61525c7b256161c64fba5693b9b17393
[rbdr/blog] / src / main.rs
1 // mod argument_parser;
2 mod configuration;
3 mod command;
4 mod constants;
5 mod gemini_parser;
6 mod generator;
7 mod archiver;
8 mod metadata;
9 mod post;
10 mod template;
11 mod utils;
12
13 use std::iter::once;
14 use std::env::args;
15 use std::io::Result;
16 use command::{available_commands, Command, help::Help};
17 use configuration::Configuration;
18
19 fn main() -> Result<()> {
20 let configuration = Configuration::new();
21 let commands = available_commands();
22 let arguments: Vec<String> = args().collect();
23
24 if let Some(command_name) = arguments.get(1) {
25 if let Some(main_command) = commands.into_iter().find(|c| c.command() == command_name) {
26 let before_commands = main_command.before_dependencies();
27 let after_commands = main_command.after_dependencies();
28
29 let command_chain: Vec<Box<dyn Command>> = before_commands
30 .into_iter()
31 .chain(once(main_command))
32 .chain(after_commands.into_iter())
33 .collect();
34
35 for command in command_chain {
36 let result = command.execute(arguments.get(2), &configuration, command_name);
37 if let Err(_) = result {
38 return result;
39 }
40 }
41
42 return Ok(())
43 }
44 }
45
46 Help::new().execute(None, &configuration, &"help".to_string())
47 }