diff --git a/src/rougail/user-data-environment/__init__.py b/src/rougail/user-data-environment/__init__.py index 767c881..a2fd8b5 100644 --- a/src/rougail/user-data-environment/__init__.py +++ b/src/rougail/user-data-environment/__init__.py @@ -1,2 +1,2 @@ -from .data import RougailUserEnvironment -__all__ = ('RougailUserEnvironment',) +from .data import RougailUserDataEnvironment +__all__ = ('RougailUserDataEnvironment',) diff --git a/src/rougail/user-data-environment/config.py b/src/rougail/user-data-environment/config.py index e2ec22d..aedf23e 100644 --- a/src/rougail/user-data-environment/config.py +++ b/src/rougail/user-data-environment/config.py @@ -25,7 +25,7 @@ def get_rougail_config(*, ) -> dict: options = """ environment: - description: Define value interactivly + description: Define value from the environment disabled: type: jinja jinja: | @@ -35,7 +35,7 @@ environment: mandatory: description: Ask values only for mandatories variables without any value negative_description: Ask values all variables - alternative_name: qm + alternative_name: envm default: false """ return {'name': 'environment', diff --git a/src/rougail/user-data-environment/data.py b/src/rougail/user-data-environment/data.py index 791c6e3..c0b7c78 100644 --- a/src/rougail/user-data-environment/data.py +++ b/src/rougail/user-data-environment/data.py @@ -87,82 +87,84 @@ class RougailUserDataEnvironment: ismulti = option.ismulti() type_obj = None type_obj = CONVERT_OPTION.get(option_type, {}).get("func") - RougailValidator.option = option - RougailValidator.option_type = {'type': option_type, - 'func': type_obj, - } - RougailValidator.ismulti = ismulti - if option_type == 'choice': - question_funtion = select - RougailValidator.default = default - kwargs['choices'] = option.value.list() - elif option_type == 'boolean': - question_funtion = confirm - else: - question_funtion = text - kwargs['validate'] = RougailValidator - args = ['📓 ' + option.description()] - if ismulti: - kwargs['multiline'] = True - if default: - kwargs['default'] = "\n".join(default) - elif default is not None: - kwargs['default'] = default - value = RougailValidator().convert_value(question_funtion(*args, **kwargs).ask(), False) - if isdefault and value == default: - option.value.reset() - else: - option.value.set(value) + print(dir(option)) + option.value.set(["78", "52"]) + #RougailValidator.option = option + #RougailValidator.option_type = {'type': option_type, + # 'func': type_obj, + # } + #RougailValidator.ismulti = ismulti + #if option_type == 'choice': + # question_funtion = select + # #RougailValidator.default = default + # kwargs['choices'] = option.value.list() + #elif option_type == 'boolean': + # question_funtion = confirm + #else: + # question_funtion = text + # kwargs['validate'] = RougailValidator + #args = ['📓 ' + option.description()] + #if ismulti: + # kwargs['multiline'] = True + # if default: + # kwargs['default'] = "\n".join(default) + #elif default is not None: + # kwargs['default'] = default + #value = RougailValidator().convert_value(question_funtion(*args, **kwargs).ask(), False) + #if isdefault and value == default: + # option.value.reset() + #else: + # option.value.set(value) -class RougailValidator(Validator): - def validate(self, document): - return self.convert_value(document.text) - - def convert_value(self, - document, - validate=True, - ): - if not self.ismulti: - value = self._convert_a_value(document, document, validate) - else: - value = [] - if document is not None: - for val in document.strip().split('\n'): - val = self._convert_a_value(val, document, validate) - if val is not None: - value.append(val) - if validate: - try: - self.option.value.set(value) - except ValueOptionError as err: - err.prefix = '' - raise ValidationError( - message=str(err), - cursor_position=len(document), - ) - return value - - def _convert_a_value(self, value, document, validate): - if value is None: - if self.option_type['type'] == 'choice': - return self.default - return - if isinstance(value, str): - value = value.strip() - if value == '': - if validate and "mandatory" in self.option.property.get(): - raise ValidationError( - message=f"Value must not be empty", - cursor_position=len(document), - ) - return - if self.option_type['func']: - try: - return self.option_type['func'](value) - except: - raise ValidationError( - message=f"Not a valid {self.option_type['type']}", - cursor_position=len(document), - ) - return value +#class RougailValidator(Validator): +# def validate(self, document): +# return self.convert_value(document.text) +# +# def convert_value(self, +# document, +# validate=True, +# ): +# if not self.ismulti: +# value = self._convert_a_value(document, document, validate) +# else: +# value = [] +# if document is not None: +# for val in document.strip().split('\n'): +# val = self._convert_a_value(val, document, validate) +# if val is not None: +# value.append(val) +# if validate: +# try: +# self.option.value.set(value) +# except ValueOptionError as err: +# err.prefix = '' +# raise ValidationError( +# message=str(err), +# cursor_position=len(document), +# ) +# return value +# +# def _convert_a_value(self, value, document, validate): +# if value is None: +# if self.option_type['type'] == 'choice': +# return self.default +# return +# if isinstance(value, str): +# value = value.strip() +# if value == '': +# if validate and "mandatory" in self.option.property.get(): +# raise ValidationError( +# message=f"Value must not be empty", +# cursor_position=len(document), +# ) +# return +# if self.option_type['func']: +# try: +# return self.option_type['func'](value) +# except: +# raise ValidationError( +# message=f"Not a valid {self.option_type['type']}", +# cursor_position=len(document), +# ) +# return value