2019-10-30 07:54:06 +01:00
|
|
|
use crate::commands::WholeStreamCommand;
|
|
|
|
use crate::errors::ShellError;
|
|
|
|
use crate::parser::CommandRegistry;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct PrependArgs {
|
2019-11-21 15:33:14 +01:00
|
|
|
row: Value,
|
2019-10-30 07:54:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Prepend;
|
|
|
|
|
|
|
|
impl WholeStreamCommand for Prepend {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"prepend"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("prepend").required(
|
|
|
|
"row value",
|
|
|
|
SyntaxShape::Any,
|
|
|
|
"the value of the row to prepend to the table",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Prepend the given row to the front of the table"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
args: CommandArgs,
|
|
|
|
registry: &CommandRegistry,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
|
|
|
args.process(registry, prepend)?.run()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn prepend(
|
|
|
|
PrependArgs { row }: PrependArgs,
|
|
|
|
RunnableContext { input, .. }: RunnableContext,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
2019-11-21 15:33:14 +01:00
|
|
|
let mut prepend: VecDeque<Value> = VecDeque::new();
|
2019-10-30 07:54:06 +01:00
|
|
|
prepend.push_back(row);
|
|
|
|
|
2019-10-30 08:04:39 +01:00
|
|
|
Ok(OutputStream::from_input(prepend.chain(input.values)))
|
2019-10-30 07:54:06 +01:00
|
|
|
}
|