Skip to main content

bake/
task.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::{Arguments, Context, Parameter, Result, Value};
5
6/// A function's command metadata and generated invocation adapter.
7pub struct Task {
8    pub(crate) name: String,
9    pub(crate) description: String,
10    pub(crate) parameters: Vec<Parameter>,
11    pub(crate) invoke: fn(&mut Context, &Arguments) -> Result<Value>,
12    pub(crate) handles_output: bool,
13    pub(crate) builtin: bool,
14}
15
16impl Task {
17    pub fn new(
18        name: impl Into<String>,
19        description: impl Into<String>,
20        parameters: Vec<Parameter>,
21        invoke: fn(&mut Context, &Arguments) -> Result<Value>,
22    ) -> Self {
23        Self {
24            name: name.into(),
25            description: description.into(),
26            parameters,
27            invoke,
28            handles_output: false,
29            builtin: false,
30        }
31    }
32
33    /// Mark a task as responsible for its own user-facing output.
34    pub fn handles_output(mut self) -> Self {
35        self.handles_output = true;
36        self
37    }
38
39    pub(crate) fn builtin(mut self) -> Self {
40        self.builtin = true;
41        self
42    }
43
44    pub fn name(&self) -> &str {
45        &self.name
46    }
47    pub fn description(&self) -> &str {
48        &self.description
49    }
50    pub fn parameters(&self) -> &[Parameter] {
51        &self.parameters
52    }
53    pub fn produces_output(&self) -> bool {
54        self.handles_output
55    }
56}