nu_cmd_lang/core_commands/
export_const.rs1use 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("const_name", SyntaxShape::VarWithOptType, "Constant name.")
21 .required(
22 "initial_value",
23 SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
24 "Equals sign followed by constant value.",
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: "Re-export a command from another module",
51 example: r#"module spam { export const foo = 3; }
52 module eggs { export use spam foo }
53 use eggs foo
54 foo
55 "#,
56 result: Some(Value::test_int(3)),
57 }]
58 }
59
60 fn search_terms(&self) -> Vec<&str> {
61 vec!["reexport", "import", "module"]
62 }
63}