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

Combine long_flag and long_flag_aliases into one API? #5138

Open
SUPERCILEX opened this issue Sep 25, 2023 · 1 comment
Open

Combine long_flag and long_flag_aliases into one API? #5138

SUPERCILEX opened this issue Sep 25, 2023 · 1 comment
Labels
A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@SUPERCILEX
Copy link
Contributor

SUPERCILEX commented Sep 25, 2023

Clap currently has https://docs.rs/clap/latest/clap/struct.Command.html#method.long_flag and https://docs.rs/clap/latest/clap/struct.Command.html#method.long_flag_aliases where long_flag_aliases does nothing without long_flag being specified. One could add a runtime warning/crash, but it's usually better to make bad states unrepresentable. The proposed solution is to unify these APIs into a long_flags method.

Actually, the reason the "alias" method variants exist is to allow having hidden long flags that don't show up in help. I think the next best solution to use a builder pattern to only allow calling the alias variants after having specified the base long flag.

@epage epage added A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change. S-waiting-on-decision Status: Waiting on a go/no-go before implementing S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing and removed S-waiting-on-decision Status: Waiting on a go/no-go before implementing labels Sep 25, 2023
@epage
Copy link
Member

epage commented Sep 25, 2023

Not finding an issue for this but I believe there has been a request to have a subcommand flag without a name. This would mean we need a canonical long_flag.

I think the next best solution to use a builder pattern to only allow calling the alias variants after having specified the base long flag.

Without what I stated above, hidden doesn't really make a difference. The desire to force a visible flag when dealing with invisible aliases applies just as much to Args.

I think the next best solution to use a builder pattern to only allow calling the alias variants after having specified the base long flag.

Relying on the type state pattern in a build API can severely complicate it especially for a runtime-focused API like clap's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

2 participants