nu_command/shells/
exit.rs

1use nu_engine::{command_prelude::*, exit::cleanup_exit};
2
3#[derive(Clone)]
4pub struct Exit;
5
6impl Command for Exit {
7    fn name(&self) -> &str {
8        "exit"
9    }
10
11    fn signature(&self) -> Signature {
12        Signature::build("exit")
13            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
14            .optional(
15                "exit_code",
16                SyntaxShape::Int,
17                "Exit code to return immediately with.",
18            )
19            .category(Category::Shells)
20    }
21
22    fn description(&self) -> &str {
23        "Exit Nu."
24    }
25
26    fn search_terms(&self) -> Vec<&str> {
27        vec!["quit", "close", "exit_code", "error_code", "logout"]
28    }
29
30    fn run(
31        &self,
32        engine_state: &EngineState,
33        stack: &mut Stack,
34        call: &Call,
35        _input: PipelineData,
36    ) -> Result<PipelineData, ShellError> {
37        let exit_code: Option<i64> = call.opt(engine_state, stack, 0)?;
38
39        let exit_code = exit_code.map_or(0, |it| it as i32);
40
41        cleanup_exit((), engine_state, exit_code);
42
43        Ok(Value::nothing(call.head).into_pipeline_data())
44    }
45
46    fn examples(&self) -> Vec<Example> {
47        vec![Example {
48            description: "Exit the current shell",
49            example: "exit",
50            result: None,
51        }]
52    }
53}