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