diff --git a/src/cli.rs b/src/cli.rs index cda5e4453..153cd0abd 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 172ada176..5c06be2a8 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 cee07a0b4..f9639b726 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 bc4625609..000000000 --- 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) -}