Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kebab-case macro #12

Open
TYTheBeast opened this issue Oct 13, 2024 · 3 comments
Open

Add kebab-case macro #12

TYTheBeast opened this issue Oct 13, 2024 · 3 comments
Labels
wontfix This will not be worked on

Comments

@TYTheBeast
Copy link

Would be really helpful if there was also a kebab-case macro, as I need it for my project in order to maintain consistency for command line arguments' format.
casey does not currently implement a kebab-case macro.

@jordy25519
Copy link
Owner

hi @TYTheBeast , thanks for the issue.
I think kebab-case may not work as it generates syntactically invalid rust code (can't compile)

could you explain your usecase a little more?
maybe a crate like heck would be more suitable here? https://crates.io/crates/heck

@TYTheBeast
Copy link
Author

Hiya jordy, my use case is in a macro in a project I've been working on, specifically this file, where I'd need the generated to string format to be kebab-case in order to keep the command line arguments for the search_item binary consistent, as the sort by arguments are kebab-case but the min/max arguments are lowercase.

My main use case is together with stringify in the macro. The issue is that in https://github.com/TYTheBeast/WynnBuilderTools-Rekindled/blob/master/src/args/item_search_args.rs in the parse_key_val_sort_by function, I have to parse from a format, currently lowercase, to my custom generated enum.
I'm no Rust expert, so perhaps you may know of a better approach? Let me know, I'm open for alternatives as well.

@jordy25519
Copy link
Owner

maybe better to convert the input string into camelcase, rather than the enum variant into kebab-case e.g:

diff --git a/src/args/generate_sort_by.rs b/src/args/generate_sort_by.rs
index 962c049..109bfbf 100644
--- a/src/args/generate_sort_by.rs
+++ b/src/args/generate_sort_by.rs
@@ -10,8 +10,9 @@ macro_rules! generate_sort_by {
             type Err = String;

             fn from_str(s: &str) -> Result<Self, Self::Err> {
-                match s.to_lowercase().as_str() {
-                    $(lower!(stringify!($variant)) => Ok(SortAndFilterBy::$variant),)*
+                use heck::ToUpperCamelCase;
+                match s.to_upper_camel_case().as_str() {
+                    $(stringify!($variant) => Ok(SortAndFilterBy::$variant),)*
                     _ => Err(format!("Unknown sort criterion: {}", s)),
                 }
             }

marking this as won't fix since kebab-case would create invalid rust syntax

@jordy25519 jordy25519 added the wontfix This will not be worked on label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants