config: Fix configuration interactive mode

This commit is contained in:
Benjamin Renard 2022-01-19 17:11:55 +01:00
parent 558da5c815
commit 0823353c0a

View file

@ -202,11 +202,11 @@ class BaseOption: # pylint: disable=too-many-instance-attributes
lines.append('')
return '\n'.join(lines)
def _ask_value(self, prompt=None):
def _ask_value(self, prompt=None, **kwargs):
""" Ask to user to enter value of this option and return it """
if self.comment:
print('# ' + self.comment)
default_value = self.get()
default_value = kwargs.get('default_value', self.get())
if not prompt:
prompt = "%s: " % self.name
if default_value is not None:
@ -261,7 +261,7 @@ class BooleanOption(BaseOption):
).lower().replace('_', '-')
)
def _ask_value(self, prompt=None):
def _ask_value(self, prompt=None, **kwargs):
""" Ask to user to enter value of this option and return it """
default_value = self.get()
prompt = "%s: " % self.name
@ -270,12 +270,12 @@ class BooleanOption(BaseOption):
else:
prompt += '[y/N] '
while True:
value = super()._ask_value(prompt).lower()
if value in ['', None]:
value = super()._ask_value(prompt, **kwargs)
if value in ['', None, default_value]:
return default_value
if value == 'y':
if value.lower() == 'y':
return True
if value == 'n':
if value.lower() == 'n':
return False
print('Invalid answer. Possible values: Y or N (case insensitive)')
@ -293,12 +293,12 @@ class FloatOption(BaseOption):
def parser_type(self):
return float
def _ask_value(self, prompt=None):
def _ask_value(self, prompt=None, **kwargs):
""" Ask to user to enter value of this option and return it """
default_value = self.get()
while True:
value = super()._ask_value()
if value in ['', None]:
value = super()._ask_value(prompt, **kwargs)
if value in ['', None, default_value]:
return default_value
try:
return float(value)
@ -323,12 +323,12 @@ class IntegerOption(BaseOption):
def parser_type(self):
return int
def _ask_value(self, prompt=None):
def _ask_value(self, prompt=None, **kwargs):
""" Ask to user to enter value of this option and return it """
default_value = self.get()
default_value = kwargs.pop('default_value', self.get())
while True:
value = super()._ask_value()
if value in ['', None]:
value = super()._ask_value(prompt, default_value=default_value, **kwargs)
if value in ['', None, default_value]:
return default_value
try:
return int(value)
@ -399,11 +399,11 @@ class PasswordOption(StringOption):
value = self.keyring_value
super().set(value)
def _ask_value(self, prompt=None):
def _ask_value(self, prompt=None, **kwargs):
""" Ask to user to enter value of this option and return it """
if self.comment:
print('# ' + self.comment)
default_value = self.get()
default_value = kwargs.pop('default_value', self.get())
if not prompt:
prompt = '%s: ' % self.name
if default_value is not None: