mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:35:00 +02:00
'first' gets first row if no amount desired given.
This commit is contained in:
@ -7,7 +7,7 @@ pub struct First;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FirstArgs {
|
||||
amount: Tagged<u64>,
|
||||
rows: Option<Tagged<u64>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for First {
|
||||
@ -16,7 +16,7 @@ impl WholeStreamCommand for First {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("first").required("amount", SyntaxShape::Int)
|
||||
Signature::build("first").optional("rows", SyntaxShape::Int)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
@ -33,8 +33,15 @@ impl WholeStreamCommand for First {
|
||||
}
|
||||
|
||||
fn first(
|
||||
FirstArgs { amount }: FirstArgs,
|
||||
FirstArgs { rows }: FirstArgs,
|
||||
context: RunnableContext,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
Ok(OutputStream::from_input(context.input.values.take(*amount)))
|
||||
|
||||
let rows_desired = if let Some(quantity) = rows {
|
||||
*quantity
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
Ok(OutputStream::from_input(context.input.values.take(rows_desired)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user