Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/officinaMusci/ambrogio into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
officinaMusci committed Apr 3, 2023
2 parents bbeaa95 + 6f0cdf6 commit 455ed33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ambrogio/cli/start.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from threading import Thread
from time import sleep

from ambrogio.cli.prompt import Prompt
from ambrogio.cli.dashboard import Dashboard
Expand Down Expand Up @@ -62,6 +63,7 @@ def start():

except Exception as e:
exit_event.set()
sleep(1)
raise e

show_dashboard_thread.join()
Expand Down
20 changes: 18 additions & 2 deletions ambrogio/procedures/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,34 @@ def from_prompt(self):
elif self.type == Path:
self.value = Prompt.path(
f"Enter a path for {self.name}",
default = self.value
default = self.value,
validate = lambda _, x: self._check_conversion(x)
)

else:
value = Prompt.text(
f"Enter value for {self.name} ({self.type.__name__})",
default = self.value,
validate = lambda _, x: self._check_type(x, self.type)
validate = lambda _, x: (
self._check_type(x, self.type)
or self._check_conversion(x)
)
)

self.value = self.type(value)

def _check_conversion(self, value: Any) -> bool:
"""
Check whether the given value can be converted to the correct type.
"""

try:
self.type(value)
except ValueError:
return False

return True

def _check_type(
self,
value: Any,
Expand Down

0 comments on commit 455ed33

Please sign in to comment.