mirror of
https://github.com/nushell/nushell.git
synced 2024-12-14 03:02:05 +01:00
b2c5af457e
This improves incremental build time when working on what was previously the root package. For example, previously all plugins would be rebuilt with a change to `src/commands/classified/external.rs`, but now only `nu-cli` will have to be rebuilt (and anything that depends on it).
47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::context::CommandRegistry;
|
|
use crate::prelude::*;
|
|
use futures::stream::StreamExt;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
|
|
|
pub struct Count;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CountArgs {}
|
|
|
|
impl WholeStreamCommand for Count {
|
|
fn name(&self) -> &str {
|
|
"count"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("count")
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Show the total number of rows."
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
args.process(registry, count)?.run()
|
|
}
|
|
}
|
|
|
|
pub fn count(
|
|
CountArgs {}: CountArgs,
|
|
RunnableContext { input, name, .. }: RunnableContext,
|
|
) -> Result<OutputStream, ShellError> {
|
|
let stream = async_stream! {
|
|
let rows: Vec<Value> = input.values.collect().await;
|
|
|
|
yield ReturnSuccess::value(UntaggedValue::int(rows.len()).into_value(name))
|
|
};
|
|
|
|
Ok(stream.to_output_stream())
|
|
}
|