mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
restructure vars_prompt and fix regression
pushed it to use the existing propmpt from display and moved the vars prompt code there also for uniformity changed vars_prompt to check extra vars vs the empty play.vars to restore 1.9 behaviour sipmlified the code as it didn't need to check for syntax again (tqm is made none prior based on that) fixes #13770
This commit is contained in:
parent
19af43ed5d
commit
1cc5ac06e7
2 changed files with 49 additions and 52 deletions
|
@ -267,13 +267,56 @@ class Display:
|
|||
self._errors[new_msg] = 1
|
||||
|
||||
@staticmethod
|
||||
def prompt(msg):
|
||||
def prompt(msg, private=False):
|
||||
prompt_string = to_bytes(msg, encoding=Display._output_encoding())
|
||||
if sys.version_info >= (3,):
|
||||
# Convert back into text on python3. We do this double conversion
|
||||
# to get rid of characters that are illegal in the user's locale
|
||||
prompt_string = to_unicode(prompt_string)
|
||||
return input(prompt_string)
|
||||
|
||||
if private:
|
||||
return getpass.getpass(msg)
|
||||
else:
|
||||
return input(prompt_string)
|
||||
|
||||
@classmethod
|
||||
def do_var_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
|
||||
|
||||
result = None
|
||||
if sys.__stdin__.isatty():
|
||||
|
||||
do_prompt = self.prompt
|
||||
|
||||
if prompt and default is not None:
|
||||
msg = "%s [%s]: " % (prompt, default)
|
||||
elif prompt:
|
||||
msg = "%s: " % prompt
|
||||
else:
|
||||
msg = 'input for %s: ' % varname
|
||||
|
||||
if confirm:
|
||||
while True:
|
||||
result = do_prompt(msg, private)
|
||||
second = do_prompt("confirm " + msg, private)
|
||||
if result == second:
|
||||
break
|
||||
display.display("***** VALUES ENTERED DO NOT MATCH ****")
|
||||
else:
|
||||
result = do_prompt(msg, private)
|
||||
else:
|
||||
result = None
|
||||
display.warning("Not prompting as we are not in interactive mode")
|
||||
|
||||
# if result is false and default is not None
|
||||
if not result and default is not None:
|
||||
result = default
|
||||
|
||||
if encrypt:
|
||||
result = do_encrypt(result, encrypt, salt_size, salt)
|
||||
|
||||
# handle utf-8 chars
|
||||
result = to_unicode(result, errors='strict')
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _output_encoding(stderr=False):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue