1//! Definitions of tasks with a static file config definition, not dependent on the application state.
2
3use std::path::{Path, PathBuf};
4
5use crate::{static_source::Definition, SpawnInTerminal, Task, TaskId};
6
7/// A single config file entry with the deserialized task definition.
8#[derive(Clone, Debug, PartialEq)]
9pub struct StaticTask {
10 id: TaskId,
11 definition: Definition,
12}
13
14impl StaticTask {
15 pub(super) fn new(id: usize, task_definition: Definition) -> Self {
16 Self {
17 id: TaskId(format!("static_{}_{}", task_definition.label, id)),
18 definition: task_definition,
19 }
20 }
21}
22
23impl Task for StaticTask {
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) -> &TaskId {
43 &self.id
44 }
45
46 fn cwd(&self) -> Option<&Path> {
47 self.definition.cwd.as_deref()
48 }
49}