mirror of
https://github.com/nushell/nushell
synced 2025-01-10 04:09:09 +00:00
39 lines
916 B
Rust
39 lines
916 B
Rust
|
use crate::commands::WholeStreamCommand;
|
||
|
use crate::errors::ShellError;
|
||
|
use crate::parser::CommandRegistry;
|
||
|
use crate::prelude::*;
|
||
|
|
||
|
pub struct Reverse;
|
||
|
|
||
|
impl WholeStreamCommand for Reverse {
|
||
|
fn run(
|
||
|
&self,
|
||
|
args: CommandArgs,
|
||
|
registry: &CommandRegistry,
|
||
|
) -> Result<OutputStream, ShellError> {
|
||
|
reverse(args, registry)
|
||
|
}
|
||
|
|
||
|
fn name(&self) -> &str {
|
||
|
"reverse"
|
||
|
}
|
||
|
|
||
|
fn signature(&self) -> Signature {
|
||
|
Signature::build("reverse")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn reverse(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||
|
let args = args.evaluate_once(registry)?;
|
||
|
let (input, _args) = args.parts();
|
||
|
|
||
|
let output = input.values.collect::<Vec<_>>();
|
||
|
|
||
|
let output = output.map(move |mut vec| {
|
||
|
vec.reverse();
|
||
|
vec.into_iter().collect::<VecDeque<_>>()
|
||
|
});
|
||
|
|
||
|
Ok(output.flatten_stream().from_input_stream())
|
||
|
}
|