nushell/src/commands/table.rs

47 lines
1.2 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)]
2019-08-13 18:33:59 +02:00
pub struct TableArgs {
full: bool,
}
2019-08-03 04:17:28 +02:00
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 {
2019-08-13 18:33:59 +02:00
Signature::build("table").switch("full")
2019-08-03 04:17:28 +02:00
}
}
2019-08-13 18:33:59 +02:00
pub fn table(
TableArgs { full }: TableArgs,
context: RunnableContext,
) -> Result<OutputStream, ShellError> {
2019-08-03 04:17:28 +02:00
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();
2019-08-13 18:33:59 +02:00
let view = TableView::from_list(&input, full);
2019-08-03 04:17:28 +02:00
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
}