mirror of
https://github.com/nushell/nushell.git
synced 2024-12-13 18:52:01 +01:00
f70c6d5d48
This commit extracts Tag, Span, Text, as well as source-related debug facilities into a new crate called nu_source. This change is much bigger than one might have expected because the previous code relied heavily on implementing inherent methods on `Tagged<T>` and `Spanned<T>`, which is no longer possible. As a result, this change creates more concrete types instead of using `Tagged<T>`. One notable example: Tagged<Value> became Value, and Value became UntaggedValue. This change clarifies the intent of the code in many places, but it does make it a big change.
48 lines
1.0 KiB
Rust
48 lines
1.0 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::errors::ShellError;
|
|
use crate::parser::CommandRegistry;
|
|
use crate::prelude::*;
|
|
|
|
#[derive(Deserialize)]
|
|
struct AppendArgs {
|
|
row: 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<Value> = VecDeque::new();
|
|
after.push_back(row);
|
|
|
|
Ok(OutputStream::from_input(input.values.chain(after)))
|
|
}
|