- if let Some(command) = commands.iter().find(|&c| c.command() == command_name) {
- return command.execute(arguments.get(2));
+ 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), &configuration, command_name);
+ if let Err(_) = result {
+ return result;
+ }
+ }
+
+ return Ok(())