From c8aa8cb842f26e91e5658d9ef118f8d0715cc205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Fri, 22 Nov 2019 03:31:58 -0500 Subject: [PATCH] debug command facelift. --- src/cli.rs | 2 +- src/commands.rs | 3 +-- src/commands/debug.rs | 27 +++++++++++++----------- src/commands/debug_value.rs | 42 ------------------------------------- 4 files changed, 17 insertions(+), 57 deletions(-) delete mode 100644 src/commands/debug_value.rs diff --git a/src/cli.rs b/src/cli.rs index cda5e44535..153cd0abdc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -326,7 +326,7 @@ pub async fn cli() -> Result<(), Box> { whole_stream_command(Version), whole_stream_command(What), whole_stream_command(Which), - whole_stream_command(DebugValue), + whole_stream_command(Debug), ]); cfg_if::cfg_if! { diff --git a/src/commands.rs b/src/commands.rs index 172ada1769..5c06be2a88 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -16,7 +16,6 @@ pub(crate) mod count; pub(crate) mod cp; pub(crate) mod date; pub(crate) mod debug; -pub(crate) mod debug_value; pub(crate) mod echo; pub(crate) mod enter; pub(crate) mod env; @@ -103,7 +102,7 @@ pub(crate) use config::Config; pub(crate) use count::Count; pub(crate) use cp::Cpy; pub(crate) use date::Date; -pub(crate) use debug_value::DebugValue; +pub(crate) use debug::Debug; pub(crate) use echo::Echo; pub(crate) use enter::Enter; pub(crate) use env::Env; diff --git a/src/commands/debug.rs b/src/commands/debug.rs index cee07a0b40..f9639b7263 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -1,9 +1,11 @@ use crate::commands::WholeStreamCommand; -use crate::errors::ShellError; use crate::prelude::*; pub struct Debug; +#[derive(Deserialize)] +pub struct DebugArgs {} + impl WholeStreamCommand for Debug { fn name(&self) -> &str { "debug" @@ -14,7 +16,7 @@ impl WholeStreamCommand for Debug { } fn usage(&self) -> &str { - "Debug input fed." + "Print the Rust debug representation of the values" } fn run( @@ -22,18 +24,19 @@ impl WholeStreamCommand for Debug { args: CommandArgs, registry: &CommandRegistry, ) -> Result { - debug(args, registry) + args.process(registry, debug_value)?.run() } } -pub fn debug(args: CommandArgs, _registry: &CommandRegistry) -> Result { - let input = args.input; +fn debug_value( + _args: DebugArgs, + RunnableContext { mut input, .. }: RunnableContext, +) -> Result { + let stream = async_stream! { + while let Some(row) = input.values.next().await { + yield ReturnSuccess::debug_value(row.clone()) + } + }; - Ok(input - .values - .map(|v| { - outln!("{:?}", v); - ReturnSuccess::value(v) - }) - .to_output_stream()) + Ok(stream) } diff --git a/src/commands/debug_value.rs b/src/commands/debug_value.rs deleted file mode 100644 index bc46256098..0000000000 --- a/src/commands/debug_value.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::commands::WholeStreamCommand; -use crate::prelude::*; - -pub struct DebugValue; - -#[derive(Deserialize)] -pub struct DebugArgs {} - -impl WholeStreamCommand for DebugValue { - fn name(&self) -> &str { - "debug" - } - - fn signature(&self) -> Signature { - Signature::build("debug") - } - - fn usage(&self) -> &str { - "Print the Rust debug representation of the values" - } - - fn run( - &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - args.process(registry, debug_value)?.run() - } -} - -fn debug_value( - _args: DebugArgs, - RunnableContext { mut input, .. }: RunnableContext, -) -> Result { - let stream = async_stream! { - while let Some(row) = input.values.next().await { - yield ReturnSuccess::debug_value(row.clone()) - } - }; - - Ok(stream) -}