nushell/src/commands/vtable.rs

48 lines
1.2 KiB
Rust
Raw Normal View History

2019-08-15 07:02:02 +02:00
use crate::commands::WholeStreamCommand;
2019-06-21 06:20:06 +02:00
use crate::errors::ShellError;
use crate::format::VTableView;
use crate::prelude::*;
2019-08-03 04:17:28 +02:00
pub struct VTable;
#[derive(Deserialize)]
pub struct VTableArgs {}
2019-08-15 07:02:02 +02:00
impl WholeStreamCommand for VTable {
2019-08-03 04:17:28 +02:00
fn name(&self) -> &str {
"vtable"
}
fn signature(&self) -> Signature {
Signature::build("vtable")
}
fn usage(&self) -> &str {
"View the contents of the pipeline as a vertical (rotated) table."
}
2019-08-03 04:17:28 +02:00
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
args.process(registry, vtable)?.run()
}
}
2019-08-06 18:26:33 +02:00
pub fn vtable(_args: VTableArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
2019-08-03 04:17:28 +02:00
let stream = async_stream_block! {
let input = context.input.into_vec().await;
if input.len() > 0 {
let mut host = context.host.lock().unwrap();
let view = VTableView::from_list(&input);
if let Some(view) = view {
handle_unexpected(&mut *host, |host| crate::format::print_view(&view, host));
}
}
};
2019-06-21 06:20:06 +02:00
2019-08-03 04:17:28 +02:00
Ok(OutputStream::new(stream))
2019-06-21 06:20:06 +02:00
}