debug command facelift.

This commit is contained in:
Andrés N. Robalino 2019-11-22 03:31:58 -05:00
parent 88c4473283
commit c8aa8cb842
4 changed files with 17 additions and 57 deletions

View File

@ -326,7 +326,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
whole_stream_command(Version), whole_stream_command(Version),
whole_stream_command(What), whole_stream_command(What),
whole_stream_command(Which), whole_stream_command(Which),
whole_stream_command(DebugValue), whole_stream_command(Debug),
]); ]);
cfg_if::cfg_if! { cfg_if::cfg_if! {

View File

@ -16,7 +16,6 @@ pub(crate) mod count;
pub(crate) mod cp; pub(crate) mod cp;
pub(crate) mod date; pub(crate) mod date;
pub(crate) mod debug; pub(crate) mod debug;
pub(crate) mod debug_value;
pub(crate) mod echo; pub(crate) mod echo;
pub(crate) mod enter; pub(crate) mod enter;
pub(crate) mod env; pub(crate) mod env;
@ -103,7 +102,7 @@ pub(crate) use config::Config;
pub(crate) use count::Count; pub(crate) use count::Count;
pub(crate) use cp::Cpy; pub(crate) use cp::Cpy;
pub(crate) use date::Date; pub(crate) use date::Date;
pub(crate) use debug_value::DebugValue; pub(crate) use debug::Debug;
pub(crate) use echo::Echo; pub(crate) use echo::Echo;
pub(crate) use enter::Enter; pub(crate) use enter::Enter;
pub(crate) use env::Env; pub(crate) use env::Env;

View File

@ -1,9 +1,11 @@
use crate::commands::WholeStreamCommand; use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::prelude::*; use crate::prelude::*;
pub struct Debug; pub struct Debug;
#[derive(Deserialize)]
pub struct DebugArgs {}
impl WholeStreamCommand for Debug { impl WholeStreamCommand for Debug {
fn name(&self) -> &str { fn name(&self) -> &str {
"debug" "debug"
@ -14,7 +16,7 @@ impl WholeStreamCommand for Debug {
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Debug input fed." "Print the Rust debug representation of the values"
} }
fn run( fn run(
@ -22,18 +24,19 @@ impl WholeStreamCommand for Debug {
args: CommandArgs, args: CommandArgs,
registry: &CommandRegistry, registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> { ) -> Result<OutputStream, ShellError> {
debug(args, registry) args.process(registry, debug_value)?.run()
} }
} }
pub fn debug(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> { fn debug_value(
let input = args.input; _args: DebugArgs,
RunnableContext { mut input, .. }: RunnableContext,
) -> Result<impl ToOutputStream, ShellError> {
let stream = async_stream! {
while let Some(row) = input.values.next().await {
yield ReturnSuccess::debug_value(row.clone())
}
};
Ok(input Ok(stream)
.values
.map(|v| {
outln!("{:?}", v);
ReturnSuccess::value(v)
})
.to_output_stream())
} }

View File

@ -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<OutputStream, ShellError> {
args.process(registry, debug_value)?.run()
}
}
fn debug_value(
_args: DebugArgs,
RunnableContext { mut input, .. }: RunnableContext,
) -> Result<impl ToOutputStream, ShellError> {
let stream = async_stream! {
while let Some(row) = input.values.next().await {
yield ReturnSuccess::debug_value(row.clone())
}
};
Ok(stream)
}