Files
oak-gpui/crates/runnable/src/static_runnable.rs
T
Piotr Osiewicz 2ec910f772 Runnables: Add oneshot runnables (#8061)
/cc @SomeoneToIgnore 
Fixes #7460 and partially addresses #7108 
Release Notes:

- N/A
2024-02-20 23:13:09 +01:00

50 lines
1.4 KiB
Rust

//! Definitions of runnables with a static file config definition, not dependent on the application state.
use std::path::{Path, PathBuf};
use crate::{static_source::Definition, Runnable, RunnableId, SpawnInTerminal};
/// A single config file entry with the deserialized runnable definition.
#[derive(Clone, Debug, PartialEq)]
pub struct StaticRunnable {
id: RunnableId,
definition: Definition,
}
impl StaticRunnable {
pub(super) fn new(id: usize, runnable: Definition) -> Self {
Self {
id: RunnableId(format!("static_{}_{}", runnable.label, id)),
definition: runnable,
}
}
}
impl Runnable for StaticRunnable {
fn exec(&self, cwd: Option<PathBuf>) -> Option<SpawnInTerminal> {
Some(SpawnInTerminal {
id: self.id.clone(),
cwd,
use_new_terminal: self.definition.use_new_terminal,
allow_concurrent_runs: self.definition.allow_concurrent_runs,
label: self.definition.label.clone(),
command: self.definition.command.clone(),
args: self.definition.args.clone(),
env: self.definition.env.clone(),
separate_shell: false,
})
}
fn name(&self) -> &str {
&self.definition.label
}
fn id(&self) -> &RunnableId {
&self.id
}
fn cwd(&self) -> Option<&Path> {
self.definition.cwd.as_deref()
}
}