mirror of
https://github.com/nushell/nushell.git
synced 2025-07-15 22:05:51 +02:00
Came from [this discussion](https://discord.com/channels/601130461678272522/1348791953784836147/1349699872059691038) on discord with @fdncred # Description Small refactoring where I rename commands from "SubCommand" to its proper name. Motivations: better clarity (although subjective), better searchable, consistency. The only commands I didn't touch were "split list" and "ansi gradient" because of name clashes. # User-Facing Changes None # Tests + Formatting cargo fmt and clippy OK # After Submitting nothing required
69 lines
1.9 KiB
Rust
69 lines
1.9 KiB
Rust
mod camel_case;
|
|
mod kebab_case;
|
|
mod pascal_case;
|
|
mod screaming_snake_case;
|
|
mod snake_case;
|
|
mod str_;
|
|
mod title_case;
|
|
|
|
pub use camel_case::StrCamelCase;
|
|
pub use kebab_case::StrKebabCase;
|
|
pub use pascal_case::StrPascalCase;
|
|
pub use screaming_snake_case::StrScreamingSnakeCase;
|
|
pub use snake_case::StrSnakeCase;
|
|
pub use str_::Str;
|
|
pub use title_case::StrTitleCase;
|
|
|
|
use nu_cmd_base::input_handler::{operate as general_operate, CmdArgument};
|
|
use nu_engine::command_prelude::*;
|
|
|
|
struct Arguments<F: Fn(&str) -> String + Send + Sync + 'static> {
|
|
case_operation: &'static F,
|
|
cell_paths: Option<Vec<CellPath>>,
|
|
}
|
|
|
|
impl<F: Fn(&str) -> String + Send + Sync + 'static> CmdArgument for Arguments<F> {
|
|
fn take_cell_paths(&mut self) -> Option<Vec<CellPath>> {
|
|
self.cell_paths.take()
|
|
}
|
|
}
|
|
|
|
pub fn operate<F>(
|
|
engine_state: &EngineState,
|
|
stack: &mut Stack,
|
|
call: &Call,
|
|
input: PipelineData,
|
|
case_operation: &'static F,
|
|
) -> Result<PipelineData, ShellError>
|
|
where
|
|
F: Fn(&str) -> String + Send + Sync + 'static,
|
|
{
|
|
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
|
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
|
|
let args = Arguments {
|
|
case_operation,
|
|
cell_paths,
|
|
};
|
|
general_operate(action, args, input, call.head, engine_state.signals())
|
|
}
|
|
|
|
fn action<F>(input: &Value, args: &Arguments<F>, head: Span) -> Value
|
|
where
|
|
F: Fn(&str) -> String + Send + Sync + 'static,
|
|
{
|
|
let case_operation = args.case_operation;
|
|
match input {
|
|
Value::String { val, .. } => Value::string(case_operation(val), head),
|
|
Value::Error { .. } => input.clone(),
|
|
_ => Value::error(
|
|
ShellError::OnlySupportsThisInputType {
|
|
exp_input_type: "string".into(),
|
|
wrong_type: input.get_type().to_string(),
|
|
dst_span: head,
|
|
src_span: input.span(),
|
|
},
|
|
head,
|
|
),
|
|
}
|
|
}
|