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

Ability to set global overrides for cyclopts.Parameters #24

Closed
Ravencentric opened this issue Dec 18, 2023 · 5 comments
Closed

Ability to set global overrides for cyclopts.Parameters #24

Ravencentric opened this issue Dec 18, 2023 · 5 comments

Comments

@Ravencentric
Copy link

Ravencentric commented Dec 18, 2023

Take this case as an example:
I do not want negatives or defaults to show up in --help for everything but one. Currently, I gotta do something like:

foo: Annotated[bool, Parameter(name="--foo", help="do foo", negative="", show_default=False)] = False,
bar: Annotated[bool, Parameter(name="--bar", help="do bar", negative="", show_default=False)] = False,
baz: Annotated[bool, Parameter(name="--baz", help="do baz")] = False,

Is it (or would it be) possible to set some global default overrides?
Example:

cyclopts.GlobalParameters(negative="", show_default=False)

foo: Annotated[bool, Parameter(name="--foo", help="do foo")] = False,
bar: Annotated[bool, Parameter(name="--bar", help="do bar")] = False,
# override show_default global for baz but negative continues to follow global default
baz: Annotated[bool, Parameter(name="--baz", help="do baz", show_default=True)] = False,
@BrianPugh
Copy link
Owner

I'm actually already working on this feature! I think it's going to look like this:

from cyclopts import App, Parameter

app = App(default_parameter=Parameter(negative="", show_default=False))

# Now all Parameters have `negative=""` and `show_default=False` as the default.

Any feedback on this proposed solution?

@Ravencentric
Copy link
Author

Looks perfect, thank you!

@BrianPugh
Copy link
Owner

This might have to wait a week or two. There's a newly merged feature in attrs that significantly simplifies the implementation. Hynek intends to do a release before new years.

@BrianPugh
Copy link
Owner

I found a workaround via the record_init_kwargs decorator.

@BrianPugh
Copy link
Owner

This has been and released in v1.2.0.

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

No branches or pull requests

2 participants