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