diff --git a/crates/nu-command/src/debug/env.rs b/crates/nu-command/src/debug/env.rs new file mode 100644 index 0000000000..b59b1f4a7f --- /dev/null +++ b/crates/nu-command/src/debug/env.rs @@ -0,0 +1,48 @@ +use nu_engine::{command_prelude::*, env_to_strings}; + +#[derive(Clone)] +pub struct DebugEnv; + +impl Command for DebugEnv { + fn name(&self) -> &str { + "debug env" + } + + fn signature(&self) -> Signature { + Signature::new(self.name()) + .input_output_type(Type::Nothing, Type::record()) + .category(Category::Debug) + } + + fn description(&self) -> &str { + "Show environment variables as external commands would get it." + } + + fn run( + &self, + engine_state: &EngineState, + stack: &mut Stack, + call: &Call, + _input: PipelineData, + ) -> Result { + Ok(PipelineData::Value( + env_to_strings(engine_state, stack)?.into_value(call.head), + None, + )) + } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Get PATH variable that externals see", + example: "debug env | get PATH!", + result: None, + }, + Example { + description: "Create a .env file", + example: r#"debug env | transpose key value | each {$"($in.key)=($in.value | to json)"} | save .env"#, + result: None, + }, + ] + } +} diff --git a/crates/nu-command/src/debug/mod.rs b/crates/nu-command/src/debug/mod.rs index 521e8948c3..19f1c6da6d 100644 --- a/crates/nu-command/src/debug/mod.rs +++ b/crates/nu-command/src/debug/mod.rs @@ -1,5 +1,6 @@ mod ast; mod debug_; +mod env; mod explain; mod info; mod inspect; @@ -19,6 +20,7 @@ mod view_span; pub use ast::Ast; pub use debug_::Debug; +pub use env::DebugEnv; pub use explain::Explain; pub use info::DebugInfo; pub use inspect::Inspect; diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index f18e3eb369..28f2bde59d 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -152,6 +152,7 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState { bind_command! { Ast, Debug, + DebugEnv, DebugInfo, DebugProfile, Explain,