nu_cmd_lang/core_commands/scope/
variables.rs

1use nu_engine::{command_prelude::*, scope::ScopeData};
2
3#[derive(Clone)]
4pub struct ScopeVariables;
5
6impl Command for ScopeVariables {
7    fn name(&self) -> &str {
8        "scope variables"
9    }
10
11    fn signature(&self) -> Signature {
12        Signature::build("scope variables")
13            .input_output_types(vec![(Type::Nothing, Type::Any)])
14            .allow_variants_without_examples(true)
15            .category(Category::Core)
16    }
17
18    fn description(&self) -> &str {
19        "Output info on the variables in the current scope."
20    }
21
22    fn run(
23        &self,
24        engine_state: &EngineState,
25        stack: &mut Stack,
26        call: &Call,
27        _input: PipelineData,
28    ) -> Result<PipelineData, ShellError> {
29        let head = call.head;
30        let mut scope_data = ScopeData::new(engine_state, stack);
31        scope_data.populate_vars();
32        Ok(Value::list(scope_data.collect_vars(head), head).into_pipeline_data())
33    }
34
35    fn examples(&self) -> Vec<Example> {
36        vec![Example {
37            description: "Show the variables in the current scope",
38            example: "scope variables",
39            result: None,
40        }]
41    }
42}
43
44#[cfg(test)]
45mod test {
46    use super::*;
47
48    #[test]
49    fn test_examples() {
50        use crate::test_examples;
51
52        test_examples(ScopeVariables {})
53    }
54}