nu_command/debug/
env.rs

1use nu_engine::{command_prelude::*, env_to_strings};
2
3#[derive(Clone)]
4pub struct DebugEnv;
5
6impl Command for DebugEnv {
7    fn name(&self) -> &str {
8        "debug env"
9    }
10
11    fn signature(&self) -> Signature {
12        Signature::new(self.name())
13            .input_output_type(Type::Nothing, Type::record())
14            .category(Category::Debug)
15    }
16
17    fn description(&self) -> &str {
18        "Show environment variables as external commands would get it."
19    }
20
21    fn run(
22        &self,
23        engine_state: &EngineState,
24        stack: &mut Stack,
25        call: &Call,
26        _input: PipelineData,
27    ) -> Result<PipelineData, ShellError> {
28        Ok(PipelineData::value(
29            env_to_strings(engine_state, stack)?.into_value(call.head),
30            None,
31        ))
32    }
33
34    fn examples(&self) -> Vec<Example> {
35        vec![
36            Example {
37                description: "Get PATH variable that externals see",
38                example: "debug env | get PATH!",
39                result: None,
40            },
41            Example {
42                description: "Create a .env file",
43                example: r#"debug env | transpose key value | each {$"($in.key)=($in.value | to json)"} | save .env"#,
44                result: None,
45            },
46        ]
47    }
48}