]> git.r.bdr.sh - rbdr/blog/blob - src/main.rs
Add status command
[rbdr/blog] / src / main.rs
1 // mod argument_parser;
2 mod configuration;
3 mod command;
4
5 use std::iter::once;
6 use std::env::args;
7 use std::io::Result;
8 use command::{available_commands, Command, help::Help};
9
10 fn main() -> Result<()> {
11 let commands = available_commands();
12 let arguments: Vec<String> = args().collect();
13
14 if let Some(command_name) = arguments.get(1) {
15 if let Some(main_command) = commands.into_iter().find(|c| c.command() == command_name) {
16 let before_commands = main_command.before_dependencies();
17 let after_commands = main_command.after_dependencies();
18
19 let command_chain: Vec<Box<dyn Command>> = before_commands
20 .into_iter()
21 .chain(once(main_command))
22 .chain(after_commands.into_iter())
23 .collect();
24
25 for command in command_chain {
26 let result = command.execute(arguments.get(2));
27 if let Err(_) = result {
28 return result;
29 }
30 }
31
32 return Ok(())
33 }
34 }
35
36 Help::new().execute(None)
37 }