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

User customizable name_transform #150

Merged
merged 5 commits into from
Apr 10, 2024
Merged

User customizable name_transform #150

merged 5 commits into from
Apr 10, 2024

Conversation

BrianPugh
Copy link
Owner

@BrianPugh BrianPugh commented Apr 10, 2024

This PR primarily adds two new fields: App.name_transform and Parameter.name_transform. The function's responsibility is to convert python identifiers to their CLI counterparts and has signature:

def name_transform(s: str) -> str:
    ...

These name transforms can be set at a global level for your app:

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.
)

They can also be set in individual subapps (subapps inherit name_transform from their parent), or in individual Annotated[...., Parameter(name_transform=my_custom_transform)] definitions.

Addresses #140.

@codecov-commenter
Copy link

codecov-commenter commented Apr 10, 2024

Codecov Report

Attention: Patch coverage is 98.38710% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 96.24%. Comparing base (f87ea85) to head (b19224c).

Files Patch % Lines
cyclopts/_convert.py 96.15% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #150      +/-   ##
==========================================
+ Coverage   96.19%   96.24%   +0.05%     
==========================================
  Files          16       16              
  Lines        1789     1813      +24     
  Branches      453      458       +5     
==========================================
+ Hits         1721     1745      +24     
  Misses         31       31              
  Partials       37       37              
Flag Coverage Δ
unittests 96.02% <98.38%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BrianPugh BrianPugh changed the title default_name_transform initial commit User customizable name_transform Apr 10, 2024
@BrianPugh BrianPugh marked this pull request as ready for review April 10, 2024 23:30
@BrianPugh BrianPugh merged commit 09320d1 into main Apr 10, 2024
15 checks passed
@BrianPugh BrianPugh deleted the name-transform branch April 10, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants