nushell/src/commands/table.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

2019-08-03 04:17:28 +02:00
use crate::commands::StaticCommand;
2019-06-21 06:20:06 +02:00
use crate::errors::ShellError;
use crate::format::TableView;
use crate::prelude::*;
2019-08-03 04:17:28 +02:00
use futures_async_stream::async_stream_block;
2019-06-21 06:20:06 +02:00
2019-08-03 04:17:28 +02:00
pub struct Table;
#[derive(Deserialize)]
pub struct TableArgs {}
impl StaticCommand for Table {
fn name(&self) -> &str {
"table"
}
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
args.process(registry, table)?.run()
2019-06-21 06:20:06 +02:00
}
2019-08-03 04:17:28 +02:00
fn signature(&self) -> Signature {
Signature::build("table")
}
}
pub fn table(_args: TableArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
let stream = async_stream_block! {
2019-08-09 06:51:21 +02:00
let input: Vec<Tagged<Value>> = context.input.into_vec().await;
2019-08-03 04:17:28 +02:00
if input.len() > 0 {
let mut host = context.host.lock().unwrap();
let view = TableView::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
}