nu_cmd_lang/core_commands/
export_def.rs1use nu_engine::command_prelude::*;
2use nu_protocol::engine::CommandType;
3
4#[derive(Clone)]
5pub struct ExportDef;
6
7impl Command for ExportDef {
8 fn name(&self) -> &str {
9 "export def"
10 }
11
12 fn description(&self) -> &str {
13 "Define a custom command and export it from a module."
14 }
15
16 fn signature(&self) -> nu_protocol::Signature {
17 Signature::build("export def")
18 .input_output_types(vec![(Type::Nothing, Type::Nothing)])
19 .required("def_name", SyntaxShape::String, "Command name.")
20 .required("params", SyntaxShape::Signature, "Parameters.")
21 .required("block", SyntaxShape::Block, "Body of the definition.")
22 .switch("env", "keep the environment defined inside the command", None)
23 .switch("wrapped", "treat unknown flags and arguments as strings (requires ...rest-like parameter in signature)", None)
24 .category(Category::Core)
25 }
26
27 fn extra_description(&self) -> &str {
28 r#"This command is a parser keyword. For details, check:
29 https://www.nushell.sh/book/thinking_in_nu.html"#
30 }
31
32 fn command_type(&self) -> CommandType {
33 CommandType::Keyword
34 }
35
36 fn run(
37 &self,
38 _engine_state: &EngineState,
39 _stack: &mut Stack,
40 _call: &Call,
41 _input: PipelineData,
42 ) -> Result<PipelineData, ShellError> {
43 Ok(PipelineData::empty())
44 }
45
46 fn examples(&self) -> Vec<Example<'_>> {
47 vec![Example {
48 description: "Define a custom command in a module and call it",
49 example: r#"module spam { export def foo [] { "foo" } }; use spam foo; foo"#,
50 result: Some(Value::test_string("foo")),
51 }]
52 }
53
54 fn search_terms(&self) -> Vec<&str> {
55 vec!["module"]
56 }
57}