remove the validator
This commit is contained in:
parent
d54ae97519
commit
776aa4a71d
3 changed files with 83 additions and 81 deletions
|
@ -1,2 +1,2 @@
|
||||||
from .data import RougailUserEnvironment
|
from .data import RougailUserDataEnvironment
|
||||||
__all__ = ('RougailUserEnvironment',)
|
__all__ = ('RougailUserDataEnvironment',)
|
||||||
|
|
|
@ -25,7 +25,7 @@ def get_rougail_config(*,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
options = """
|
options = """
|
||||||
environment:
|
environment:
|
||||||
description: Define value interactivly
|
description: Define value from the environment
|
||||||
disabled:
|
disabled:
|
||||||
type: jinja
|
type: jinja
|
||||||
jinja: |
|
jinja: |
|
||||||
|
@ -35,7 +35,7 @@ environment:
|
||||||
mandatory:
|
mandatory:
|
||||||
description: Ask values only for mandatories variables without any value
|
description: Ask values only for mandatories variables without any value
|
||||||
negative_description: Ask values all variables
|
negative_description: Ask values all variables
|
||||||
alternative_name: qm
|
alternative_name: envm
|
||||||
default: false
|
default: false
|
||||||
"""
|
"""
|
||||||
return {'name': 'environment',
|
return {'name': 'environment',
|
||||||
|
|
|
@ -87,82 +87,84 @@ class RougailUserDataEnvironment:
|
||||||
ismulti = option.ismulti()
|
ismulti = option.ismulti()
|
||||||
type_obj = None
|
type_obj = None
|
||||||
type_obj = CONVERT_OPTION.get(option_type, {}).get("func")
|
type_obj = CONVERT_OPTION.get(option_type, {}).get("func")
|
||||||
RougailValidator.option = option
|
print(dir(option))
|
||||||
RougailValidator.option_type = {'type': option_type,
|
option.value.set(["78", "52"])
|
||||||
'func': type_obj,
|
#RougailValidator.option = option
|
||||||
}
|
#RougailValidator.option_type = {'type': option_type,
|
||||||
RougailValidator.ismulti = ismulti
|
# 'func': type_obj,
|
||||||
if option_type == 'choice':
|
# }
|
||||||
question_funtion = select
|
#RougailValidator.ismulti = ismulti
|
||||||
RougailValidator.default = default
|
#if option_type == 'choice':
|
||||||
kwargs['choices'] = option.value.list()
|
# question_funtion = select
|
||||||
elif option_type == 'boolean':
|
# #RougailValidator.default = default
|
||||||
question_funtion = confirm
|
# kwargs['choices'] = option.value.list()
|
||||||
else:
|
#elif option_type == 'boolean':
|
||||||
question_funtion = text
|
# question_funtion = confirm
|
||||||
kwargs['validate'] = RougailValidator
|
#else:
|
||||||
args = ['📓 ' + option.description()]
|
# question_funtion = text
|
||||||
if ismulti:
|
# kwargs['validate'] = RougailValidator
|
||||||
kwargs['multiline'] = True
|
#args = ['📓 ' + option.description()]
|
||||||
if default:
|
#if ismulti:
|
||||||
kwargs['default'] = "\n".join(default)
|
# kwargs['multiline'] = True
|
||||||
elif default is not None:
|
# if default:
|
||||||
kwargs['default'] = default
|
# kwargs['default'] = "\n".join(default)
|
||||||
value = RougailValidator().convert_value(question_funtion(*args, **kwargs).ask(), False)
|
#elif default is not None:
|
||||||
if isdefault and value == default:
|
# kwargs['default'] = default
|
||||||
option.value.reset()
|
#value = RougailValidator().convert_value(question_funtion(*args, **kwargs).ask(), False)
|
||||||
else:
|
#if isdefault and value == default:
|
||||||
option.value.set(value)
|
# option.value.reset()
|
||||||
|
#else:
|
||||||
|
# option.value.set(value)
|
||||||
|
|
||||||
|
|
||||||
class RougailValidator(Validator):
|
#class RougailValidator(Validator):
|
||||||
def validate(self, document):
|
# def validate(self, document):
|
||||||
return self.convert_value(document.text)
|
# return self.convert_value(document.text)
|
||||||
|
#
|
||||||
def convert_value(self,
|
# def convert_value(self,
|
||||||
document,
|
# document,
|
||||||
validate=True,
|
# validate=True,
|
||||||
):
|
# ):
|
||||||
if not self.ismulti:
|
# if not self.ismulti:
|
||||||
value = self._convert_a_value(document, document, validate)
|
# value = self._convert_a_value(document, document, validate)
|
||||||
else:
|
# else:
|
||||||
value = []
|
# value = []
|
||||||
if document is not None:
|
# if document is not None:
|
||||||
for val in document.strip().split('\n'):
|
# for val in document.strip().split('\n'):
|
||||||
val = self._convert_a_value(val, document, validate)
|
# val = self._convert_a_value(val, document, validate)
|
||||||
if val is not None:
|
# if val is not None:
|
||||||
value.append(val)
|
# value.append(val)
|
||||||
if validate:
|
# if validate:
|
||||||
try:
|
# try:
|
||||||
self.option.value.set(value)
|
# self.option.value.set(value)
|
||||||
except ValueOptionError as err:
|
# except ValueOptionError as err:
|
||||||
err.prefix = ''
|
# err.prefix = ''
|
||||||
raise ValidationError(
|
# raise ValidationError(
|
||||||
message=str(err),
|
# message=str(err),
|
||||||
cursor_position=len(document),
|
# cursor_position=len(document),
|
||||||
)
|
# )
|
||||||
return value
|
# return value
|
||||||
|
#
|
||||||
def _convert_a_value(self, value, document, validate):
|
# def _convert_a_value(self, value, document, validate):
|
||||||
if value is None:
|
# if value is None:
|
||||||
if self.option_type['type'] == 'choice':
|
# if self.option_type['type'] == 'choice':
|
||||||
return self.default
|
# return self.default
|
||||||
return
|
# return
|
||||||
if isinstance(value, str):
|
# if isinstance(value, str):
|
||||||
value = value.strip()
|
# value = value.strip()
|
||||||
if value == '':
|
# if value == '':
|
||||||
if validate and "mandatory" in self.option.property.get():
|
# if validate and "mandatory" in self.option.property.get():
|
||||||
raise ValidationError(
|
# raise ValidationError(
|
||||||
message=f"Value must not be empty",
|
# message=f"Value must not be empty",
|
||||||
cursor_position=len(document),
|
# cursor_position=len(document),
|
||||||
)
|
# )
|
||||||
return
|
# return
|
||||||
if self.option_type['func']:
|
# if self.option_type['func']:
|
||||||
try:
|
# try:
|
||||||
return self.option_type['func'](value)
|
# return self.option_type['func'](value)
|
||||||
except:
|
# except:
|
||||||
raise ValidationError(
|
# raise ValidationError(
|
||||||
message=f"Not a valid {self.option_type['type']}",
|
# message=f"Not a valid {self.option_type['type']}",
|
||||||
cursor_position=len(document),
|
# cursor_position=len(document),
|
||||||
)
|
# )
|
||||||
return value
|
# return value
|
||||||
|
|
Loading…
Reference in a new issue