]>
Commit | Line | Data |
---|---|---|
d620665f RBR |
1 | // mod argument_parser; |
2 | mod configuration; | |
3 | mod command; | |
a9c6be41 RBR |
4 | mod constants; |
5 | mod metadata; | |
d620665f | 6 | |
5f81d796 | 7 | use std::iter::once; |
d620665f RBR |
8 | use std::env::args; |
9 | use std::io::Result; | |
d620665f | 10 | use command::{available_commands, Command, help::Help}; |
a9c6be41 | 11 | use configuration::Configuration; |
d620665f RBR |
12 | |
13 | fn main() -> Result<()> { | |
a9c6be41 | 14 | let configuration = Configuration::new(); |
d620665f | 15 | let commands = available_commands(); |
d620665f RBR |
16 | let arguments: Vec<String> = args().collect(); |
17 | ||
18 | if let Some(command_name) = arguments.get(1) { | |
5f81d796 RBR |
19 | if let Some(main_command) = commands.into_iter().find(|c| c.command() == command_name) { |
20 | let before_commands = main_command.before_dependencies(); | |
21 | let after_commands = main_command.after_dependencies(); | |
22 | ||
23 | let command_chain: Vec<Box<dyn Command>> = before_commands | |
24 | .into_iter() | |
25 | .chain(once(main_command)) | |
26 | .chain(after_commands.into_iter()) | |
27 | .collect(); | |
28 | ||
29 | for command in command_chain { | |
a9c6be41 | 30 | let result = command.execute(arguments.get(2), &configuration, command_name); |
5f81d796 RBR |
31 | if let Err(_) = result { |
32 | return result; | |
33 | } | |
34 | } | |
35 | ||
36 | return Ok(()) | |
d620665f RBR |
37 | } |
38 | } | |
39 | ||
a9c6be41 | 40 | Help::new().execute(None, &configuration, &"help".to_string()) |
d620665f | 41 | } |