mirror of
https://github.com/nushell/nushell.git
synced 2025-05-21 23:23:49 +00:00
with the `help` command to explore and list all commands available. Enter will also try to see if the location to be entered is an existing Nu command, if it is it will let you inspect the command under `help`. This provides baseline needed so we can iterate on it.
48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::errors::ShellError;
|
|
use crate::format::TableView;
|
|
use crate::prelude::*;
|
|
use futures_async_stream::async_stream_block;
|
|
|
|
pub struct Table;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct TableArgs {}
|
|
|
|
impl WholeStreamCommand for Table {
|
|
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."
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
args.process(registry, table)?.run()
|
|
}
|
|
}
|
|
|
|
pub fn table(_args: 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);
|
|
if let Some(view) = view {
|
|
handle_unexpected(&mut *host, |host| crate::format::print_view(&view, host));
|
|
}
|
|
}
|
|
};
|
|
|
|
Ok(OutputStream::new(stream))
|
|
}
|