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