]> git.r.bdr.sh - rbdr/blog/blame_incremental - src/main.rs
Add mac
[rbdr/blog] / src / main.rs
... / ...
CommitLineData
1mod configuration;
2mod command;
3mod constants;
4mod gemini_parser;
5mod generator;
6mod archiver;
7mod metadata;
8mod post;
9mod template;
10mod utils;
11mod remote;
12
13use std::iter::once;
14use std::env::args;
15use std::io::Result;
16use command::{available_commands, Command, help::Help};
17use configuration::Configuration;
18
19fn main() -> Result<()> {
20 let result = run();
21
22 if cfg!(debug_assertions) {
23 result
24 } else {
25 match result {
26 Ok(_) => Ok(()),
27 Err(e) => {
28 eprintln!("{}", e);
29 std::process::exit(1);
30 }
31 }
32 }
33}
34
35fn run() -> Result<()> {
36 let configuration = Configuration::new();
37 let commands = available_commands();
38 let arguments: Vec<String> = args().collect();
39
40 if let Some(command_name) = arguments.get(1) {
41 if let Some(main_command) = commands.into_iter().find(|c| c.command() == command_name) {
42 let before_commands = main_command.before_dependencies();
43 let after_commands = main_command.after_dependencies();
44
45 let command_chain: Vec<Box<dyn Command>> = before_commands
46 .into_iter()
47 .chain(once(main_command))
48 .chain(after_commands.into_iter())
49 .collect();
50
51 for command in command_chain {
52 let result = command.execute(arguments.get(2), &configuration, command_name);
53 if let Err(_) = result {
54 return result;
55 }
56 }
57
58 return Ok(())
59 }
60 }
61
62 Help::new().execute(None, &configuration, &"help".to_string())
63}