feat: support of password type

This commit is contained in:
egarette@silique.fr 2024-09-02 16:24:52 +02:00
parent fee60fc00a
commit da16ffffc8
3 changed files with 22 additions and 1 deletions

View file

@ -0,0 +1,2 @@
from .data import RougailUserDataQuestionary
__all__ = ('RougailUserDataQuestionary',)

View file

@ -34,8 +34,18 @@ questionary:
{% endif %}
mandatory:
description: Ask values only for mandatories variables without any value
negative_description: Ask values all variables
alternative_name: qm
default: false
show_secrets:
description: Show secrets instead of obscuring them
negative_description: Obscuring secrets instead of show them
alternative_name: qs
type: boolean
default:
type: variable
variable: __.exporter.show_secrets
optional: true
"""
return {'name': 'questionary',
'process': 'user data',

View file

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from rougail.object_model import CONVERT_OPTION
from rougail.config import RougailConfig
from tiramisu.error import ValueOptionError
from questionary import text, select, confirm, Validator, ValidationError, print as qprint
from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint
class RougailUserDataQuestionary:
def __init__(self,
@ -33,6 +33,13 @@ class RougailUserDataQuestionary:
self.config = config
if rougailconfig is None:
rougailconfig = RougailConfig
user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data:
user_data.append('questionary')
rougailconfig['step.user_data'] = user_data
user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data:
raise Exception('questionary is not set in step.user_data')
self.rougailconfig = rougailconfig
self.errors = []
self.warnings = []
@ -92,6 +99,8 @@ class RougailUserDataQuestionary:
kwargs['choices'] = option.value.list()
elif option_type == 'boolean':
question_funtion = confirm
elif option_type == 'secret' and not self.rougailconfig['questionary.show_secrets']:
question_funtion = password
else:
question_funtion = text
kwargs['validate'] = RougailValidator