nu_command/experimental/
job_flush.rs

1use nu_engine::command_prelude::*;
2
3#[derive(Clone)]
4pub struct JobFlush;
5
6impl Command for JobFlush {
7    fn name(&self) -> &str {
8        "job flush"
9    }
10
11    fn description(&self) -> &str {
12        "Clear this job's mailbox."
13    }
14
15    fn extra_description(&self) -> &str {
16        r#"
17This command removes all messages in the mailbox of the current job.
18If a message is received while this command is executing, it may also be discarded.
19"#
20    }
21
22    fn signature(&self) -> nu_protocol::Signature {
23        Signature::build("job flush")
24            .category(Category::Experimental)
25            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
26            .allow_variants_without_examples(true)
27    }
28
29    fn search_terms(&self) -> Vec<&str> {
30        vec![]
31    }
32
33    fn run(
34        &self,
35        engine_state: &EngineState,
36        _stack: &mut Stack,
37        call: &Call,
38        _input: PipelineData,
39    ) -> Result<PipelineData, ShellError> {
40        let mut mailbox = engine_state
41            .current_job
42            .mailbox
43            .lock()
44            .expect("failed to acquire lock");
45
46        mailbox.clear();
47
48        Ok(Value::nothing(call.head).into_pipeline_data())
49    }
50
51    fn examples(&self) -> Vec<Example<'_>> {
52        vec![Example {
53            example: "job flush",
54            description: "Clear the mailbox of the current job.",
55            result: None,
56        }]
57    }
58}