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