Accept password values that start with a dash (#1752)#1841
Open
barry3406 wants to merge 1 commit intodbcli:mainfrom
Open
Accept password values that start with a dash (#1752)#1841barry3406 wants to merge 1 commit intodbcli:mainfrom
barry3406 wants to merge 1 commit intodbcli:mainfrom
Conversation
click 8.3+ marks any option declared with a flag_value as
_flag_needs_value=True, which triggers a parser heuristic that refuses
values beginning with a dash. That turned
mycli --password=-rocks
into 'Error: No such option: -r'. Wrap the command in a
_PasswordFriendlyCommand subclass that disables the heuristic on the
password option and injects the flag-value sentinel itself when the
option is used bare, preserving the prompt-for-password behavior.
Contributor
|
Hi! Thanks for working on this! I have a different idea, expressed in #1842, which is to let It seems important that the sentinel value not be a string. |
Author
|
Hey, took a look at #1842 — your approach is cleaner, no argument there. Mine keeps bare |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
mycli --password=-rockscurrently fails withError: No such option: -r. Click 8.3+ sets_flag_needs_value=Trueon any option declared with aflag_value, which in turn triggers a parser heuristic that refuses values beginning with a dash — so the password value gets reinterpreted as short options. See #1752.The fix wraps
click_entrypointin a small_PasswordFriendlyCommandsubclass that disables the heuristic on the password option and injects the flag-value sentinel itself when-p/--pass/--passwordis used bare, preserving the prompt-for-password behavior. The integer sentinel becomes a unique string since injected argv values have to pass through the param type. Covered by a new parametrized test that exercises the dash-value forms (--password=-rocks,-p-rocks,--pass=-rocks, etc.) alongside the existing--password=foo,--password foo, and-prockscases to guard against regressions.Fixes #1752.
Checklist
changelog.mdfile.AUTHORSfile (or it's already there).