mirror of
https://github.com/nushell/nushell
synced 2025-01-04 01:09:05 +00:00
47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::errors::ShellError;
|
|
use crate::parser::CommandRegistry;
|
|
use crate::prelude::*;
|
|
|
|
#[derive(Deserialize)]
|
|
struct AppendArgs {
|
|
row: Tagged<Value>,
|
|
}
|
|
|
|
pub struct Append;
|
|
|
|
impl WholeStreamCommand for Append {
|
|
fn name(&self) -> &str {
|
|
"append"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("append").required(
|
|
"row value",
|
|
SyntaxShape::Any,
|
|
"the value of the row to append to the table",
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Append the given row to the table"
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
args.process(registry, append)?.run()
|
|
}
|
|
}
|
|
|
|
fn append(
|
|
AppendArgs { row }: AppendArgs,
|
|
RunnableContext { input, .. }: RunnableContext,
|
|
) -> Result<OutputStream, ShellError> {
|
|
let mut after: VecDeque<Tagged<Value>> = VecDeque::new();
|
|
after.push_back(row);
|
|
|
|
Ok(OutputStream::from_input(input.values.chain(after)))
|
|
}
|