Skip to main content

nu_cmd_lang/core_commands/
export_const.rs

1use nu_engine::command_prelude::*;
2use nu_protocol::engine::CommandType;
3
4#[derive(Clone)]
5pub struct ExportConst;
6
7impl Command for ExportConst {
8    fn name(&self) -> &str {
9        "export const"
10    }
11
12    fn description(&self) -> &str {
13        "Use parse-time constant from a module and export them from this module."
14    }
15
16    fn signature(&self) -> nu_protocol::Signature {
17        Signature::build("export const")
18            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
19            .allow_variants_without_examples(true)
20            .required(
21                "const_name",
22                SyntaxShape::VarWithOptType,
23                "The constant name to create and export.",
24            )
25            .required(
26                "initial_value",
27                SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
28                "Equals sign followed by constant value.",
29            )
30            .category(Category::Core)
31    }
32
33    fn extra_description(&self) -> &str {
34        r#"This command is a parser keyword. For details, check:
35  https://www.nushell.sh/book/thinking_in_nu.html"#
36    }
37
38    fn command_type(&self) -> CommandType {
39        CommandType::Keyword
40    }
41
42    fn run(
43        &self,
44        _engine_state: &EngineState,
45        _stack: &mut Stack,
46        _call: &Call,
47        _input: PipelineData,
48    ) -> Result<PipelineData, ShellError> {
49        Ok(PipelineData::empty())
50    }
51
52    fn examples(&self) -> Vec<Example<'_>> {
53        vec![Example {
54            description: "Re-export a constant from another module.",
55            example: r#"module spam { export const foo = 3; }
56    module eggs { export use spam foo }
57    use eggs foo
58    foo
59            "#,
60            result: Some(Value::test_int(3)),
61        }]
62    }
63
64    fn search_terms(&self) -> Vec<&str> {
65        vec!["reexport", "import", "module"]
66    }
67}