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

feat(derive): add a 'prefix = ' attr for structs #4250

Closed
wants to merge 1 commit into from

Conversation

wfraser
Copy link

@wfraser wfraser commented Sep 23, 2022

I took the code sample I wrote up in #3513 and rebased it onto the current master (at 4.0.0-rc.2). I'm currently using this feature in a large codebase and some folks on at least two other companies I've spoken to have found it useful as well.

Implementation notes: this works very similarly to rename_all and rename_all_env in that it takes effect in the Name::translate() method (and also in Name::raw to prevent collisions), and how it is propagated from parent struct down to child fields. It's nice that the entire implementation lives in clap_derive and needs no support from clap itself.

I've added a test which illustrates how it works. In real usage, the sub-structs would be defined in different modules or even in different crates; the whole point of this is to permit uniform re-use of a set of related options across several binaries in a large codebase.

@wfraser wfraser changed the title derive: add a 'prefix = ' attr for structs feat(derive): add a 'prefix = ' attr for structs Sep 23, 2022
This prepends a given string to all arg names in a struct.
@epage
Copy link
Member

epage commented Sep 23, 2022

While draft PRs can be useful for demonstrating ideas, I don't think we are at the point in #3513 to be ready for implementation. There are still areas of discussion that need resolution.

@epage epage closed this Sep 23, 2022
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