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

Automatic conversion from underscore to hyphen #140

Closed
nguyenvulong opened this issue Mar 28, 2024 · 3 comments
Closed

Automatic conversion from underscore to hyphen #140

nguyenvulong opened this issue Mar 28, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@nguyenvulong
Copy link

This is not really a bug report but a "behavior note". As requested by Brian, I created an issue here for further reference. You may want to mention it in the README section.

Original discussion tiangolo/typer#233 (comment)

This behavior comes from Click

The workaround is using a lambda function as mentioned here tiangolo/typer#341 (comment)

I think if there're many requests from user, please consider adding an option to keep the opt name as-is. Thank you.

@BrianPugh
Copy link
Owner

Hey @nguyenvulong! Thank you for opening up this issue! I'm actually thinking about tackling it in a similar way here in Cyclopts. Both App and Parameter would take in an optional argument, name_transform, which defaults to the following function:

def default_name_transform(name: str) -> str:
    return name.lower().replace("_", "-").strip("-")

You could then set your own like:

app = App(
    name_transform=lambda name: name,  # don't modify the name at all. This applies to command names.
    default_parameter=Parameter(name_transform=lambda name: name),  # This applies to parameter names.
)

What do you think of this proposal?

@BrianPugh BrianPugh added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 28, 2024
@nguyenvulong
Copy link
Author

Hi @BrianPugh
Yeah that looks good to me.

Thank you.

@BrianPugh
Copy link
Owner

Addressed in #150 and is now part of release v2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants