nu_cmd_lang/core_commands/scope/
commands.rs1use nu_engine::{command_prelude::*, scope::ScopeData};
2
3#[derive(Clone)]
4pub struct ScopeCommands;
5
6impl Command for ScopeCommands {
7 fn name(&self) -> &str {
8 "scope commands"
9 }
10
11 fn signature(&self) -> Signature {
12 Signature::build("scope commands")
13 .input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::Any)))])
14 .allow_variants_without_examples(true)
15 .category(Category::Core)
16 }
17
18 fn description(&self) -> &str {
19 "Output info on the commands 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_decls();
32 Ok(Value::list(scope_data.collect_commands(head), head).into_pipeline_data())
33 }
34
35 fn examples(&self) -> Vec<Example> {
36 vec![Example {
37 description: "Show the commands in the current scope",
38 example: "scope commands",
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(ScopeCommands {})
53 }
54}