1use nu_engine::command_prelude::*;
2
3#[derive(Clone)]
4pub struct Panic;
5
6impl Command for Panic {
7 fn name(&self) -> &str {
8 "panic"
9 }
10
11 fn description(&self) -> &str {
12 "Causes nushell to panic."
13 }
14
15 fn search_terms(&self) -> Vec<&str> {
16 vec!["crash", "throw"]
17 }
18
19 fn signature(&self) -> nu_protocol::Signature {
20 Signature::build("panic")
21 .input_output_types(vec![(Type::Nothing, Type::Nothing)])
22 .optional(
23 "msg",
24 SyntaxShape::String,
25 "The custom message for the panic.",
26 )
27 .category(Category::Debug)
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 maybe_msg: String = call
38 .opt(engine_state, stack, 0)?
39 .unwrap_or("Panic!".to_string());
40 panic!("{}", maybe_msg)
41 }
42
43 fn examples(&self) -> Vec<Example> {
44 vec![Example {
45 description: "Panic with a custom message",
46 example: "panic 'This is a custom panic message'",
47 result: None,
48 }]
49 }
50}