aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-02-24 23:20:14 +0000
committerRuben Beltran del Rio <git@r.bdr.sh>2024-02-24 23:20:14 +0000
commit5f81d796fed4e4efbaf6dbed7d3c69481afddeb3 (patch)
treec99b6232a003f5a04e9ba0624d842aac8ac43462 /src/main.rs
parent442ebaf901a8ca686ce769325054e1f393d43b7c (diff)
Add status command
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index cb258c2..bf1e184 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,24 +2,34 @@
mod configuration;
mod command;
+use std::iter::once;
use std::env::args;
use std::io::Result;
-use configuration::Configuration;
use command::{available_commands, Command, help::Help};
fn main() -> Result<()> {
- let configuration = Configuration::new();
let commands = available_commands();
-
- println!("CONFIGURATION DIRECTORY: {}", configuration.config_directory.display());
- println!("DATA DIRECTORY: {}", configuration.data_directory.display());
- println!("OUTPUT DIRECTORY: {}", configuration.output_directory.display());
-
let arguments: Vec<String> = args().collect();
if let Some(command_name) = arguments.get(1) {
- 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));
+ if let Err(_) = result {
+ return result;
+ }
+ }
+
+ return Ok(())
}
}