required_unless_present on positional arguments #5218
Replies: 1 comment 2 replies
-
The problem isn't Positional arguments should generally be used when the position has a clear meaning. I find in most cases with complex positionals, that isn't true and that options would be a better fit. |
Beta Was this translation helpful? Give feedback.
-
I'm running into an issue when trying to use required_unless_present on a positional argument. When I do so, and the given flag is present, it's still requiring that argument.
Consider a simplified version of htpasswd's interface:
I would expect this to work OK, but it panics:
or, with allow_missing_positional turned on, an error which implies that it's still expecting exactly two arguments:
Is there a way to make the parser select arguments in this way? Is there a workaround to allow properly parsing htpasswd-compatible arguments?
Example playground demo
Beta Was this translation helpful? Give feedback.
All reactions