aboutsummaryrefslogtreecommitdiff
path: root/cli/new/reader.py
diff options
context:
space:
mode:
authorJoris2023-09-17 12:23:47 +0200
committerJoris2023-09-17 12:23:47 +0200
commit1ebc55c72a1a17293bbf4ad86e0177a10a794750 (patch)
tree5fce0ea3a011ccbae85b0d3927f8ac33099585fb /cli/new/reader.py
parentc236facb4d4c277773c83f1a4ee85b48833d7e67 (diff)
Make app packageable
Diffstat (limited to 'cli/new/reader.py')
-rw-r--r--cli/new/reader.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/cli/new/reader.py b/cli/new/reader.py
new file mode 100644
index 0000000..eacd70b
--- /dev/null
+++ b/cli/new/reader.py
@@ -0,0 +1,55 @@
+def required(label):
+ value = input(f'{label}: ').strip()
+ if value:
+ print()
+ return value
+ else:
+ return required(label)
+
+def multi_line(label):
+ lines = ''
+ print(f'{label}, type [end] to finish:\n')
+ while True:
+ value = input()
+ if value.strip() == '[end]':
+ break
+ elif value.strip():
+ lines += f'{value.strip()}\n'
+ print()
+ return lines.strip()
+
+def optional(label):
+ value = input(f'{label} (optional): ').strip()
+ print()
+ return value
+
+def non_empty_list(label):
+ value = input(f'{label} (separated by commas): ')
+ values = [x.strip() for x in value.split(',') if x.strip()]
+ if len(values) > 0:
+ print()
+ return values
+ else:
+ return non_empty_list(label)
+
+def integer(label):
+ value = input(f'{label}: ').strip()
+ if value.isdigit():
+ print()
+ return int(value)
+ else:
+ return integer(label)
+
+def choices(label, xs):
+ pp_choices = '/'.join(xs)
+ value = input(f'{label} [{pp_choices}] ')
+ if value in xs:
+ print()
+ return value
+ else:
+ return choices(label, xs)
+
+def confirm(message):
+ if choices(message, ['y', 'n']) == 'n':
+ print('\nStopping.')
+ exit(1)