]> git.r.bdr.sh - rbdr/blog/blame_incremental - src/main.rs
Allow sync up and down
[rbdr/blog] / src / main.rs
... / ...
CommitLineData
1// mod argument_parser;
2mod configuration;
3mod command;
4mod constants;
5mod gemini_parser;
6mod generator;
7mod archiver;
8mod metadata;
9mod post;
10mod template;
11mod utils;
12mod remote;
13
14use std::iter::once;
15use std::env::args;
16use std::io::Result;
17use command::{available_commands, Command, help::Help};
18use configuration::Configuration;
19
20fn 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}