Commands to engine p (#3426)

* hash and into converted

* keep command to engine p

* Update int.rs

Co-authored-by: JT <jonathandturner@users.noreply.github.com>
This commit is contained in:
Fernando Herrera
2021-05-15 05:11:07 +01:00
committed by GitHub
parent d79a3130b8
commit 07760b4129
10 changed files with 88 additions and 141 deletions

View File

@@ -6,11 +6,6 @@ use nu_source::Tagged;
pub struct Command;
#[derive(Deserialize)]
pub struct Arguments {
rows: Option<Tagged<usize>>,
}
impl WholeStreamCommand for Command {
fn name(&self) -> &str {
"keep"
@@ -28,7 +23,7 @@ impl WholeStreamCommand for Command {
"Keep the number of rows only."
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
keep(args)
}
@@ -53,15 +48,17 @@ impl WholeStreamCommand for Command {
}
}
fn keep(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { rows }, input) = args.process()?;
fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once()?;
let rows: Option<Tagged<usize>> = args.opt(0)?;
let rows_desired = if let Some(quantity) = rows {
*quantity
} else {
1
};
Ok(input.take(rows_desired).to_action_stream())
Ok(args.input.take(rows_desired).to_output_stream())
}
#[cfg(test)]

View File

@@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
"Keeps rows until the condition matches."
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let call_info = args.evaluate_once()?;
@@ -93,7 +93,7 @@ impl WholeStreamCommand for SubCommand {
!matches!(result, Ok(ref v) if v.is_true())
})
.to_action_stream())
.to_output_stream())
}
}

View File

@@ -26,7 +26,7 @@ impl WholeStreamCommand for SubCommand {
"Keeps rows while the condition matches."
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let call_info = args.evaluate_once()?;
@@ -92,7 +92,7 @@ impl WholeStreamCommand for SubCommand {
matches!(result, Ok(ref v) if v.is_true())
})
.to_action_stream())
.to_output_stream())
}
}