Skip to content

Commit 82fcd1b

Browse files
committed
refactor: Add strip_handler to clean input results and integrate into get_input
1 parent 21f4fe5 commit 82fcd1b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bugscanx/utils/common.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
"text": [required]
2424
}
2525

26+
def strip_handler(handler, strip_input):
27+
def wrapped(params):
28+
result = handler(params)
29+
if strip_input and isinstance(result, str):
30+
return result.strip()
31+
return result
32+
return wrapped
33+
2634
INPUT_HANDLERS = {
2735
"choice": lambda params: select(**params).execute(),
2836
"file": lambda params: filepath(**params).execute(),
@@ -43,6 +51,7 @@ def get_input(
4351
instruction="",
4452
mandatory=True,
4553
allow_comma_separated=True,
54+
strip_input=True,
4655
**kwargs
4756
):
4857
common_params = {
@@ -53,6 +62,7 @@ def get_input(
5362
"style": style,
5463
"instruction": instruction + (":" if instruction else ""),
5564
"mandatory": mandatory,
65+
"transformer": transformer
5666
}
5767

5868
if validators is None and validate_input:
@@ -82,7 +92,7 @@ def get_input(
8292
if not handler:
8393
raise ValueError(f"Unsupported input_type: {input_type}")
8494

85-
return handler(common_params)
95+
return strip_handler(handler, strip_input)(common_params)
8696

8797
def get_confirm(
8898
message,

0 commit comments

Comments
 (0)