mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-21 05:07:35 +03:00
fix(core): convert command arguments to camel case (#1753)
This commit is contained in:
parent
ea28d01691
commit
e84949524c
@ -176,6 +176,8 @@ fn parse_arg(command: &Ident, arg: &FnArg) -> syn::Result<TokenStream2> {
|
||||
));
|
||||
}
|
||||
|
||||
let key = snake_case_to_camel_case(key);
|
||||
|
||||
Ok(quote!(::tauri::command::CommandArg::from_command(
|
||||
::tauri::command::CommandItem {
|
||||
name: stringify!(#command),
|
||||
@ -184,3 +186,24 @@ fn parse_arg(command: &Ident, arg: &FnArg) -> syn::Result<TokenStream2> {
|
||||
}
|
||||
)))
|
||||
}
|
||||
|
||||
fn snake_case_to_camel_case(s: String) -> String {
|
||||
if s.as_str().contains('_') {
|
||||
let mut camel = String::with_capacity(s.len());
|
||||
let mut to_upper = false;
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'_' => to_upper = true,
|
||||
c if to_upper => {
|
||||
camel.push(c.to_ascii_uppercase());
|
||||
to_upper = false;
|
||||
}
|
||||
c => camel.push(c),
|
||||
}
|
||||
}
|
||||
|
||||
camel
|
||||
} else {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user