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