port capitalize to engine-p (#3794)

Part of #3390.
This commit is contained in:
Sam Bordo 2021-07-23 03:13:11 -04:00 committed by GitHub
parent f9f39c0a1c
commit 57073cc6cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,9 +2,7 @@ use crate::prelude::*;
use nu_engine::WholeStreamCommand; use nu_engine::WholeStreamCommand;
use nu_errors::ShellError; use nu_errors::ShellError;
use nu_protocol::ShellTypeName; use nu_protocol::ShellTypeName;
use nu_protocol::{ use nu_protocol::{ColumnPath, Primitive, Signature, SyntaxShape, UntaggedValue, Value};
ColumnPath, Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
};
use nu_source::Tag; use nu_source::Tag;
use nu_value_ext::ValueExt; use nu_value_ext::ValueExt;
@ -30,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
"capitalizes text" "capitalizes text"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
operate(args) operate(args)
} }
@ -43,7 +41,7 @@ impl WholeStreamCommand for SubCommand {
} }
} }
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> { fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (options, input) = ( let (options, input) = (
Arguments { Arguments {
column_paths: args.rest(0)?, column_paths: args.rest(0)?,
@ -54,7 +52,7 @@ fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(input Ok(input
.map(move |v| { .map(move |v| {
if options.column_paths.is_empty() { if options.column_paths.is_empty() {
ReturnSuccess::value(action(&v, v.tag())?) action(&v, v.tag())
} else { } else {
let mut ret = v; let mut ret = v;
@ -65,10 +63,10 @@ fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
)?; )?;
} }
ReturnSuccess::value(ret) Ok(ret)
} }
}) })
.into_action_stream()) .into_input_stream())
} }
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> { fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {