mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-15 17:42:43 +02:00
fix(ahk): gen multi-word + multiple flags correctly
This commit is contained in:
Generated
+1
-1
@@ -212,7 +212,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive-ahk"
|
name = "derive-ahk"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "derive-ahk"
|
name = "derive-ahk"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|||||||
+17
-4
@@ -5,12 +5,15 @@
|
|||||||
use ::std::clone::Clone;
|
use ::std::clone::Clone;
|
||||||
use ::std::convert::From;
|
use ::std::convert::From;
|
||||||
use ::std::convert::Into;
|
use ::std::convert::Into;
|
||||||
|
use ::std::format;
|
||||||
use ::std::iter::Extend;
|
use ::std::iter::Extend;
|
||||||
use ::std::iter::Iterator;
|
use ::std::iter::Iterator;
|
||||||
use ::std::matches;
|
use ::std::matches;
|
||||||
use ::std::option::Option::Some;
|
use ::std::option::Option::Some;
|
||||||
|
use ::std::string::String;
|
||||||
use ::std::string::ToString;
|
use ::std::string::ToString;
|
||||||
use ::std::unreachable;
|
use ::std::unreachable;
|
||||||
|
use ::std::vec::Vec;
|
||||||
|
|
||||||
use ::quote::quote;
|
use ::quote::quote;
|
||||||
use ::syn::parse_macro_input;
|
use ::syn::parse_macro_input;
|
||||||
@@ -102,7 +105,8 @@ pub fn ahk_function(input: ::proc_macro::TokenStream) -> ::proc_macro::TokenStre
|
|||||||
let flag_idents_clone = flag_idents.clone();
|
let flag_idents_clone = flag_idents.clone();
|
||||||
let flags = quote! {#(--#flag_idents_clone) *}
|
let flags = quote! {#(--#flag_idents_clone) *}
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace("- - ", "--");
|
.replace("- - ", "--")
|
||||||
|
.replace('_', "-");
|
||||||
|
|
||||||
let called_flag_arguments = quote! {#(%#flag_idents%) *}
|
let called_flag_arguments = quote! {#(%#flag_idents%) *}
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -110,19 +114,28 @@ pub fn ahk_function(input: ::proc_macro::TokenStream) -> ::proc_macro::TokenStre
|
|||||||
.replace("% ", "%")
|
.replace("% ", "%")
|
||||||
.replace("%%", "% %");
|
.replace("%%", "% %");
|
||||||
|
|
||||||
|
let flags_split: Vec<_> = flags.split(' ').collect();
|
||||||
|
let flag_args_split: Vec<_> = called_flag_arguments.split(' ').collect();
|
||||||
|
let mut consolidated_flags: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
for (idx, flag) in flags_split.iter().enumerate() {
|
||||||
|
consolidated_flags.push(format!("{} {}", flag, flag_args_split[idx]));
|
||||||
|
}
|
||||||
|
|
||||||
|
let all_flags = consolidated_flags.join(" ");
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl AhkFunction for #name {
|
impl AhkFunction for #name {
|
||||||
fn generate_ahk_function() -> String {
|
fn generate_ahk_function() -> String {
|
||||||
::std::format!(r#"
|
::std::format!(r#"
|
||||||
{}({}) {{
|
{}({}) {{
|
||||||
Run, komorebic.exe {} {} {} {}, , Hide
|
Run, komorebic.exe {} {} {}, , Hide
|
||||||
}}"#,
|
}}"#,
|
||||||
::std::stringify!(#name),
|
::std::stringify!(#name),
|
||||||
#all_arguments,
|
#all_arguments,
|
||||||
::std::stringify!(#name).to_kebab_case(),
|
::std::stringify!(#name).to_kebab_case(),
|
||||||
#called_arguments,
|
#called_arguments,
|
||||||
#flags,
|
#all_flags,
|
||||||
#called_flag_arguments
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user