From ac5ad4578386e4ef1098f8921cecda516175a7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Wed, 29 Jan 2020 02:46:54 -0500 Subject: [PATCH] Pretty Nu print default, pretty print regular secondary as raw flag. (#1302) --- src/commands/debug.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/commands/debug.rs b/src/commands/debug.rs index ff6722242..a783d8176 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -6,7 +6,9 @@ use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; pub struct Debug; #[derive(Deserialize)] -pub struct DebugArgs {} +pub struct DebugArgs { + raw: bool, +} impl WholeStreamCommand for Debug { fn name(&self) -> &str { @@ -14,7 +16,7 @@ impl WholeStreamCommand for Debug { } fn signature(&self) -> Signature { - Signature::build("debug") + Signature::build("debug").switch("raw", "Prints the raw value representation.") } fn usage(&self) -> &str { @@ -31,13 +33,19 @@ impl WholeStreamCommand for Debug { } fn debug_value( - _args: DebugArgs, + DebugArgs { raw }: DebugArgs, RunnableContext { input, .. }: RunnableContext, ) -> Result { Ok(input .values - .map(|v| { - ReturnSuccess::value(UntaggedValue::string(format!("{:#?}", v)).into_untagged_value()) + .map(move |v| { + if raw { + ReturnSuccess::value( + UntaggedValue::string(format!("{:#?}", v)).into_untagged_value(), + ) + } else { + ReturnSuccess::debug_value(v) + } }) .to_output_stream()) }