nu_cmd_lang/core_commands/
ignore.rs

1use nu_engine::command_prelude::*;
2use nu_protocol::{ByteStreamSource, OutDest, engine::StateWorkingSet};
3
4#[derive(Clone)]
5pub struct Ignore;
6
7impl Command for Ignore {
8    fn name(&self) -> &str {
9        "ignore"
10    }
11
12    fn description(&self) -> &str {
13        "Ignore the output of the previous command in the pipeline."
14    }
15
16    fn signature(&self) -> nu_protocol::Signature {
17        Signature::build("ignore")
18            .input_output_types(vec![(Type::Any, Type::Nothing)])
19            .category(Category::Core)
20    }
21
22    fn search_terms(&self) -> Vec<&str> {
23        vec!["silent", "quiet", "out-null"]
24    }
25
26    fn is_const(&self) -> bool {
27        true
28    }
29
30    fn run(
31        &self,
32        _engine_state: &EngineState,
33        _stack: &mut Stack,
34        _call: &Call,
35        mut input: PipelineData,
36    ) -> Result<PipelineData, ShellError> {
37        if let PipelineData::ByteStream(stream, _) = &mut input {
38            #[cfg(feature = "os")]
39            if let ByteStreamSource::Child(child) = stream.source_mut() {
40                child.ignore_error(true);
41            }
42        }
43        input.drain()?;
44        Ok(PipelineData::empty())
45    }
46
47    fn run_const(
48        &self,
49        _working_set: &StateWorkingSet,
50        _call: &Call,
51        input: PipelineData,
52    ) -> Result<PipelineData, ShellError> {
53        input.drain()?;
54        Ok(PipelineData::empty())
55    }
56
57    fn examples(&self) -> Vec<Example<'_>> {
58        vec![Example {
59            description: "Ignore the output of an echo command",
60            example: "echo done | ignore",
61            result: Some(Value::nothing(Span::test_data())),
62        }]
63    }
64
65    fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
66        (Some(OutDest::Null), None)
67    }
68}
69
70#[cfg(test)]
71mod test {
72    #[test]
73    fn test_examples() {
74        use super::Ignore;
75        use crate::test_examples;
76        test_examples(Ignore {})
77    }
78}