Finish up heuristic for table printing

This commit is contained in:
Jonathan Turner
2019-08-14 04:33:59 +12:00
parent 123b1856c8
commit 156e72f694
3 changed files with 46 additions and 32 deletions

View File

@@ -7,7 +7,9 @@ use futures_async_stream::async_stream_block;
pub struct Table;
#[derive(Deserialize)]
pub struct TableArgs {}
pub struct TableArgs {
full: bool,
}
impl StaticCommand for Table {
fn name(&self) -> &str {
@@ -21,16 +23,19 @@ impl StaticCommand for Table {
args.process(registry, table)?.run()
}
fn signature(&self) -> Signature {
Signature::build("table")
Signature::build("table").switch("full")
}
}
pub fn table(_args: TableArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
pub fn table(
TableArgs { full }: TableArgs,
context: RunnableContext,
) -> Result<OutputStream, ShellError> {
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = context.input.into_vec().await;
if input.len() > 0 {
let mut host = context.host.lock().unwrap();
let view = TableView::from_list(&input);
let view = TableView::from_list(&input, full);
if let Some(view) = view {
handle_unexpected(&mut *host, |host| crate::format::print_view(&view, host));
}