1 // mod argument_parser;
17 use command::{available_commands, Command, help::Help};
18 use configuration::Configuration;
20 fn main() -> Result<()> {
23 if cfg!(debug_assertions) {
29 eprintln!("Error: {}", e);
30 std::process::exit(1);
36 fn run() -> Result<()> {
37 let configuration = Configuration::new();
38 let commands = available_commands();
39 let arguments: Vec<String> = args().collect();
41 if let Some(command_name) = arguments.get(1) {
42 if let Some(main_command) = commands.into_iter().find(|c| c.command() == command_name) {
43 let before_commands = main_command.before_dependencies();
44 let after_commands = main_command.after_dependencies();
46 let command_chain: Vec<Box<dyn Command>> = before_commands
48 .chain(once(main_command))
49 .chain(after_commands.into_iter())
52 for command in command_chain {
53 let result = command.execute(arguments.get(2), &configuration, command_name);
54 if let Err(_) = result {
63 Help::new().execute(None, &configuration, &"help".to_string())