port string case commands to engine-p (#3649)

Port snake_case and friends to engine-p syntax.

Part of #3390.
This commit is contained in:
Eli Flanagan 2021-06-18 23:01:18 -04:00 committed by GitHub
parent 9e39284de9
commit 51c685aa99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for SubCommand {
"converts a string to camelCase" "converts a string to camelCase"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
operate(args, &to_camel_case) operate(args, &to_camel_case)
} }

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for SubCommand {
"converts a string to kebab-case" "converts a string to kebab-case"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
operate(args, &to_kebab_case) operate(args, &to_kebab_case)
} }

View File

@ -7,7 +7,7 @@ pub mod snake_case;
use crate::prelude::*; use crate::prelude::*;
use nu_errors::ShellError; use nu_errors::ShellError;
use nu_protocol::ShellTypeName; use nu_protocol::ShellTypeName;
use nu_protocol::{ColumnPath, Primitive, ReturnSuccess, UntaggedValue, Value}; use nu_protocol::{ColumnPath, Primitive, UntaggedValue, Value};
use nu_source::Tag; use nu_source::Tag;
use nu_value_ext::ValueExt; use nu_value_ext::ValueExt;
@ -20,7 +20,7 @@ struct Arguments {
column_paths: Vec<ColumnPath>, column_paths: Vec<ColumnPath>,
} }
pub fn operate<F>(args: CommandArgs, case_operation: &'static F) -> Result<ActionStream, ShellError> pub fn operate<F>(args: CommandArgs, case_operation: &'static F) -> Result<OutputStream, ShellError>
where where
F: Fn(&str) -> String + Send + Sync + 'static, F: Fn(&str) -> String + Send + Sync + 'static,
{ {
@ -34,7 +34,7 @@ where
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(), &case_operation)?) action(&v, v.tag(), &case_operation)
} else { } else {
let mut ret = v; let mut ret = v;
@ -45,10 +45,10 @@ where
)?; )?;
} }
ReturnSuccess::value(ret) Ok(ret)
} }
}) })
.into_action_stream()) .into_input_stream())
} }
pub fn action<F>( pub fn action<F>(

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for SubCommand {
"converts a string to PascalCase" "converts a string to PascalCase"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
operate(args, &to_pascal_case) operate(args, &to_pascal_case)
} }

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for SubCommand {
"converts a string to SCREAMING_SNAKE_CASE" "converts a string to SCREAMING_SNAKE_CASE"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
operate(args, &to_screaming_snake_case) operate(args, &to_screaming_snake_case)
} }

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for SubCommand {
"converts a string to snake_case" "converts a string to snake_case"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
operate(args, &to_snake_case) operate(args, &to_snake_case)
} }