nushell/src/commands/table.rs

51 lines
1.3 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::TableView;
use crate::prelude::*;
2019-08-03 04:17:28 +02:00
pub struct Table;
#[derive(Deserialize)]
2019-08-15 18:49:07 +02:00
pub struct TableArgs {}
2019-08-03 04:17:28 +02:00
2019-08-15 07:02:02 +02:00
impl WholeStreamCommand for Table {
2019-08-03 04:17:28 +02:00
fn name(&self) -> &str {
"table"
}
fn signature(&self) -> Signature {
Signature::build("table")
}
fn usage(&self) -> &str {
"View the contents of the pipeline as a table."
}
2019-08-03 04:17:28 +02:00
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
}
2019-08-15 18:49:07 +02:00
pub fn table(_args: TableArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
2019-09-28 02:05:18 +02:00
let stream = async_stream! {
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-15 18:49:07 +02:00
let view = TableView::from_list(&input);
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-09-28 02:05:18 +02:00
// Needed for async_stream to type check
if false {
yield ReturnSuccess::value(Value::nothing().tagged_unknown());
}
2019-08-03 04:17:28 +02:00
};
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
}