mirror of
https://github.com/nushell/nushell.git
synced 2025-04-26 06:08:21 +02: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.
43 lines
983 B
Rust
43 lines
983 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 name(&self) -> &str {
|
|
"reverse"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("reverse")
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Reverses the table."
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
reverse(args, registry)
|
|
}
|
|
}
|
|
|
|
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())
|
|
}
|