nu_cmd_lang/core_commands/
export_module.rs

1use nu_engine::command_prelude::*;
2use nu_protocol::engine::CommandType;
3
4#[derive(Clone)]
5pub struct ExportModule;
6
7impl Command for ExportModule {
8    fn name(&self) -> &str {
9        "export module"
10    }
11
12    fn description(&self) -> &str {
13        "Export a custom module from a module."
14    }
15
16    fn signature(&self) -> nu_protocol::Signature {
17        Signature::build("export module")
18            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
19            .allow_variants_without_examples(true)
20            .required("module", SyntaxShape::String, "Module name or module path.")
21            .optional(
22                "block",
23                SyntaxShape::Block,
24                "Body of the module if 'module' parameter is not a path.",
25            )
26            .category(Category::Core)
27    }
28
29    fn extra_description(&self) -> &str {
30        r#"This command is a parser keyword. For details, check:
31  https://www.nushell.sh/book/thinking_in_nu.html"#
32    }
33
34    fn command_type(&self) -> CommandType {
35        CommandType::Keyword
36    }
37
38    fn run(
39        &self,
40        _engine_state: &EngineState,
41        _stack: &mut Stack,
42        _call: &Call,
43        _input: PipelineData,
44    ) -> Result<PipelineData, ShellError> {
45        Ok(PipelineData::empty())
46    }
47
48    fn examples(&self) -> Vec<Example> {
49        vec![Example {
50            description: "Define a custom command in a submodule of a module and call it",
51            example: r#"module spam {
52        export module eggs {
53            export def foo [] { "foo" }
54        }
55    }
56    use spam eggs
57    eggs foo"#,
58            result: Some(Value::test_string("foo")),
59        }]
60    }
61}
62
63#[cfg(test)]
64mod test {
65    use super::*;
66    #[test]
67    fn test_examples() {
68        use crate::test_examples;
69
70        test_examples(ExportModule {})
71    }
72}