]> git.r.bdr.sh - rbdr/blog/blame - src/main.rs
Generate and archive blog, allow publishing
[rbdr/blog] / src / main.rs
CommitLineData
d620665f
RBR
1// mod argument_parser;
2mod configuration;
3mod command;
a9c6be41 4mod constants;
29982470
RBR
5mod gemini_parser;
6mod generator;
6352ebb0 7mod archiver;
a9c6be41 8mod metadata;
29982470
RBR
9mod post;
10mod template;
6352ebb0 11mod utils;
d620665f 12
5f81d796 13use std::iter::once;
d620665f
RBR
14use std::env::args;
15use std::io::Result;
d620665f 16use command::{available_commands, Command, help::Help};
a9c6be41 17use configuration::Configuration;
d620665f
RBR
18
19fn main() -> Result<()> {
a9c6be41 20 let configuration = Configuration::new();
d620665f 21 let commands = available_commands();
d620665f
RBR
22 let arguments: Vec<String> = args().collect();
23
24 if let Some(command_name) = arguments.get(1) {
5f81d796
RBR
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 {
a9c6be41 36 let result = command.execute(arguments.get(2), &configuration, command_name);
5f81d796
RBR
37 if let Err(_) = result {
38 return result;
39 }
40 }
41
42 return Ok(())
d620665f
RBR
43 }
44 }
45
a9c6be41 46 Help::new().execute(None, &configuration, &"help".to_string())
d620665f 47}