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