nu_cmd_lang/core_commands/
export.rs

1use nu_engine::{command_prelude::*, get_full_help};
2use nu_protocol::engine::CommandType;
3
4#[derive(Clone)]
5pub struct ExportCommand;
6
7impl Command for ExportCommand {
8    fn name(&self) -> &str {
9        "export"
10    }
11
12    fn signature(&self) -> Signature {
13        Signature::build("export")
14            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
15            .category(Category::Core)
16    }
17
18    fn description(&self) -> &str {
19        "Export definitions or environment variables from a module."
20    }
21
22    fn extra_description(&self) -> &str {
23        r#"This command is a parser keyword. For details, check:
24  https://www.nushell.sh/book/thinking_in_nu.html"#
25    }
26
27    fn command_type(&self) -> CommandType {
28        CommandType::Keyword
29    }
30
31    fn run(
32        &self,
33        engine_state: &EngineState,
34        stack: &mut Stack,
35        call: &Call,
36        _input: PipelineData,
37    ) -> Result<PipelineData, ShellError> {
38        Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
39    }
40
41    fn examples(&self) -> Vec<Example> {
42        vec![Example {
43            description: "Export a definition from a module",
44            example: r#"module utils { export def my-command [] { "hello" } }; use utils my-command; my-command"#,
45            result: Some(Value::test_string("hello")),
46        }]
47    }
48
49    fn search_terms(&self) -> Vec<&str> {
50        vec!["module"]
51    }
52}