Browse Source

Add basic action running

Samuel W. Flint 3 years ago
parent
commit
bae594d63d
2 changed files with 19 additions and 2 deletions
  1. 2 2
      src/lib/action.rs
  2. 17 0
      src/lib/run.rs

+ 2 - 2
src/lib/action.rs

@@ -10,9 +10,9 @@ pub struct Action {
     #[serde(default)]
     description: String,
     #[serde(default)]
-    command: String,
+    pub command: String,
     #[serde(default)]
-    disabled: bool,
+    pub disabled: bool,
 }
 
 pub fn add(config: &mut Config, name: &String, description: &String, command: &String) {

+ 17 - 0
src/lib/run.rs

@@ -7,8 +7,25 @@ use crate::lib::{
     action::Action
 };
 
+
+use std::process::Command;
+
 pub fn run(config: &Config, names: Values<'_>) {
     for name in names {
         println!("Running {}...", name)
     }
 }
+pub fn run_action(config: &Config, name: String) {
+    let action = config.actions.get(&name.to_string());
+    match action {
+        Some(action) => {
+            if !action.disabled {
+                Command::new("sh")
+                    .arg("-c")
+                    .arg(&action.command)
+                    .spawn();
+            }
+        },
+        None => panic!("No known action named \"{}\".", name)
+    }
+}