Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise CleoException(self.question.error_message % selected)
selected_choices = selected_choices.split(',')
else:
selected_choices = [selected]
multiselect_choices = []
for value in selected_choices:
results = []
for key, choice in enumerate(self.values):
if choice == value:
results.append(key)
if len(results) > 1:
raise CleoException(
'The provided answer is ambiguous. Value should be one of %s.'
% ' or '.join(results)
)
try:
result = self.values.index(value)
result = self.values[result]
except ValueError:
try:
value = int(value)
if value < len(self.values):
result = self.values[value]
else:
result = False
def autocompleter_values(self, values):
"""
Sets values for the autocompleter.
:param values: The autocomplete values
:type values: list or None
"""
if values is not None and not isinstance(values, list):
raise CleoException("Autocompleter values can be either a list or None.")
if self.hidden:
raise CleoException("A hidden question cannot use the autocompleter.")
self._autocompleter_values = values
def _formatter_estimated(self):
if not self._max:
raise CleoException(
'Unable to display the estimated time '
'if the maximum number of steps is not set.'
)
if not self._step:
estimated = 0
else:
estimated = (
round(
(time.time() - self._start_time) / self._step
* self._max
)
)
return estimated
def add_row(self, row):
if isinstance(row, TableSeparator):
self._rows.append(row)
return self
if not isinstance(row, list):
raise CleoException('A row must be a list or a TableSeparator instance.')
self._rows.append(row)
return self
:param indicator_change_interval: Change interval in milliseconds
:type indicator_change_interval: int
:param indicator_values: Animated indicator characters
:type indicator_values: list or None
"""
self._output = output
if fmt is None:
fmt = self._determine_best_format()
if indicator_values is None:
indicator_values = ['-', '\\', '|', '/']
if len(indicator_values) < 2:
raise CleoException('Must have at least 2 indicator value characters.')
self.format = self.formats[fmt]
self.indicator_change_interval = indicator_change_interval
self.indicator_values = indicator_values
self._message = None
self._indicator_update_time = None
self._started = False
self._indicator_current = 0
# Auto
self._auto_running = None
self._auto_thread = None
self.start_time = time.time()
def finish(self, message, reset_indicator=False):
"""
Finish the indicator with message.
"""
if not self._started:
raise CleoException('Progress indicator has not yet been started.')
if self._auto_thread:
self._auto_running.set()
self._auto_thread.join()
self._message = message
if reset_indicator:
self._indicator_current = 0
self._display()
self._output.writeln('')
self._started = False
from ..application import Application
self.output = output
if isinstance(obj, InputArgument):
self._describe_input_argument(obj, **options)
elif isinstance(obj, InputOption):
self._describe_input_option(obj, **options)
elif isinstance(obj, InputDefinition):
self._describe_input_definition(obj, **options)
elif isinstance(obj, BaseCommand):
self._describe_command(obj, **options)
elif isinstance(obj, Application):
self._describe_application(obj, **options)
else:
raise CleoException(
'Object of type "%s" is not describable' % obj.__class__.__name__
)
:param column_index: Colun index
:type column_index: int
:param name: The name of the style
:type name: str or TableStyle
:rtype: Table
"""
column_index = int(column_index)
if isinstance(name, TableStyle):
self._column_styles[column_index] = name
elif name in self.styles:
self._column_styles[column_index] = self.styles[name]
else:
raise CleoException('Style "%s" is not defined.' % name)
def set_padding_char(self, padding_char):
if not padding_char:
raise CleoException("Padding char must not be empty")
self.padding_char = padding_char
return self