static_runnable.rs

 1//! Definitions of runnables with a static file config definition, not dependent on the application state.
 2
 3use std::path::{Path, PathBuf};
 4
 5use crate::{static_source::Definition, Runnable, RunnableId, SpawnInTerminal};
 6
 7/// A single config file entry with the deserialized runnable definition.
 8#[derive(Clone, Debug, PartialEq)]
 9pub struct StaticRunnable {
10    id: RunnableId,
11    definition: Definition,
12}
13
14impl StaticRunnable {
15    pub(super) fn new(id: usize, runnable: Definition) -> Self {
16        Self {
17            id: RunnableId(format!("static_{}_{}", runnable.label, id)),
18            definition: runnable,
19        }
20    }
21}
22
23impl Runnable for StaticRunnable {
24    fn exec(&self, cwd: Option<PathBuf>) -> Option<SpawnInTerminal> {
25        Some(SpawnInTerminal {
26            id: self.id.clone(),
27            cwd,
28            use_new_terminal: self.definition.use_new_terminal,
29            allow_concurrent_runs: self.definition.allow_concurrent_runs,
30            label: self.definition.label.clone(),
31            command: self.definition.command.clone(),
32            args: self.definition.args.clone(),
33            env: self.definition.env.clone(),
34            separate_shell: false,
35        })
36    }
37
38    fn name(&self) -> &str {
39        &self.definition.label
40    }
41
42    fn id(&self) -> &RunnableId {
43        &self.id
44    }
45
46    fn cwd(&self) -> Option<&Path> {
47        self.definition.cwd.as_deref()
48    }
49}