]> git.r.bdr.sh - rbdr/blog/blame - src/main.rs
Remove unused JS code and docs
[rbdr/blog] / src / main.rs
CommitLineData
d620665f
RBR
1// mod argument_parser;
2mod configuration;
3mod command;
4
5f81d796 5use std::iter::once;
d620665f
RBR
6use std::env::args;
7use std::io::Result;
d620665f
RBR
8use command::{available_commands, Command, help::Help};
9
10fn main() -> Result<()> {
d620665f 11 let commands = available_commands();
d620665f
RBR
12 let arguments: Vec<String> = args().collect();
13
14 if let Some(command_name) = arguments.get(1) {
5f81d796
RBR
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(())
d620665f
RBR
33 }
34 }
35
36 Help::new().execute(None)
37}