[BugFix] Revamp the usage of list syntax on routines (#6450)

* using list syntax on routines

* black

* ruff

* simplify

* black
This commit is contained in:
Henrique Joaquim
2024-05-22 12:46:19 +01:00
committed by GitHub
parent 8baf4d74b2
commit f91791dbf9
7 changed files with 30 additions and 21 deletions

View File

@@ -355,7 +355,7 @@ class CLIController(BaseController):
"--input",
help="Select multiple inputs to be replaced in the routine and separated by commas. E.g. GME,AMC,BTC-USD",
dest="routine_args",
type=lambda s: [str(item) for item in s.split(",")],
type=str,
)
parser.add_argument(
"-e",
@@ -431,17 +431,22 @@ class CLIController(BaseController):
with open(routine_path) as fp:
raw_lines = list(fp)
script_inputs = []
# Capture ARGV either as list if args separated by commas or as single value
if ns_parser.routine_args:
script_inputs = (
ns_parser.routine_args
if "," not in ns_parser.routine_args
else ns_parser.routine_args.split(",")
if routine_args := ns_parser.routine_args:
pattern = r"\[(.*?)\]"
matches = re.findall(pattern, routine_args)
for match in matches:
routine_args = routine_args.replace(f"[{match}]", "")
script_inputs.append(match)
script_inputs.extend(
[val for val in routine_args.split(",") if val]
)
err, parsed_script = parse_openbb_script(
raw_lines=raw_lines,
script_inputs=script_inputs if ns_parser.routine_args else None,
raw_lines=raw_lines, script_inputs=script_inputs
)
# If there err output is not an empty string then it means there was an
@@ -546,7 +551,6 @@ def run_cli(jobs_cmds: Optional[List[str]] = None, test_mode=False):
t_controller.print_help()
while ret_code:
# There is a command in the queue
if t_controller.queue and len(t_controller.queue) > 0:
# If the command is quitting the menu we want to return in here