From 69334f541b486b8e34b119e82c863ae2e2d243f6 Mon Sep 17 00:00:00 2001 From: Hilary James Oliver Date: Sun, 13 Aug 2023 17:33:09 +1200 Subject: [PATCH] Centralize cli flow options. --- cylc/flow/flow_mgr.py | 25 +++++++++++++++++++++++++ cylc/flow/scripts/reset.py | 30 ++---------------------------- cylc/flow/scripts/trigger.py | 29 ++--------------------------- 3 files changed, 29 insertions(+), 55 deletions(-) diff --git a/cylc/flow/flow_mgr.py b/cylc/flow/flow_mgr.py index 5316658267c..c80fcc0d4ba 100644 --- a/cylc/flow/flow_mgr.py +++ b/cylc/flow/flow_mgr.py @@ -39,8 +39,33 @@ ) +def add_flow_opts(parser): + parser.add_option( + "--flow", action="append", dest="flow", metavar="FLOW", + help=f'Assign the triggered task to all active flows ("{FLOW_ALL}");' + f' no flow ("{FLOW_NONE}"); a new flow ("{FLOW_NEW}");' + f' or a specific flow (e.g. "2"). The default is "{FLOW_ALL}".' + ' Reuse the option to assign multiple specific flows.' + ) + + parser.add_option( + "--meta", metavar="DESCRIPTION", action="store", + dest="flow_descr", default=None, + help=f"description of triggered flow (with --flow={FLOW_NEW})." + ) + + parser.add_option( + "--wait", action="store_true", default=False, dest="flow_wait", + help="Wait for merge with current active flows before flowing on." + ) + + def validate_flow_opts(options): """Check validity of flow-related CLI options.""" + if options.flow is None: + # Default to all active flows + options.flow = [FLOW_ALL] + for val in options.flow: val = val.strip() if val in [FLOW_NONE, FLOW_NEW, FLOW_ALL]: diff --git a/cylc/flow/scripts/reset.py b/cylc/flow/scripts/reset.py index 9bb4081cfa7..91feb8853c8 100755 --- a/cylc/flow/scripts/reset.py +++ b/cylc/flow/scripts/reset.py @@ -49,7 +49,7 @@ ) from cylc.flow.terminal import cli_function from cylc.flow.flow_mgr import ( - FLOW_ALL, + add_flow_opts, validate_flow_opts ) from cylc.flow.task_pool import REC_CLI_PREREQ @@ -112,28 +112,7 @@ def get_option_parser() -> COP: action="append", default=None, dest="prerequisites" ) - parser.add_option( - "-f", "--flow", metavar="INT", - help=( - "Flow to attribute the outputs to. Default: all active flows." - " If the task is already spawned, use current flows and" - " merge new flow numbers if specified." - ), - action="store", default=None, dest="flow" - ) - - parser.add_option( - "-m", "--meta", metavar="STRING", - help="With --flow=new: Description of the new flow.", - action="store", default=None, dest="flow_descr" - ) - - parser.add_option( - "-w", "--wait", - help="Wait for merge with current active flows before continuing", - action="store_true", default=False, dest="flow_wait" - ) - + add_flow_opts(parser) return parser @@ -205,12 +184,7 @@ async def run(options: 'Values', workflow_id: str, *tokens_list) -> None: @cli_function(get_option_parser) def main(parser: COP, options: 'Values', *ids) -> None: - - if options.flow is None: - options.flow = [FLOW_ALL] # default to all active flows - validate_flow_opts(options) - call_multi( partial(run, options), *ids, diff --git a/cylc/flow/scripts/trigger.py b/cylc/flow/scripts/trigger.py index 05cf3c1da81..9d27fc38bd1 100755 --- a/cylc/flow/scripts/trigger.py +++ b/cylc/flow/scripts/trigger.py @@ -52,9 +52,7 @@ ) from cylc.flow.terminal import cli_function from cylc.flow.flow_mgr import ( - FLOW_NONE, - FLOW_NEW, - FLOW_ALL, + add_flow_opts, validate_flow_opts ) @@ -92,26 +90,7 @@ def get_option_parser() -> COP: multiworkflow=True, argdoc=[FULL_ID_MULTI_ARG_DOC], ) - - parser.add_option( - "--flow", action="append", dest="flow", metavar="FLOW", - help=f"Assign the triggered task to all active flows ({FLOW_ALL});" - f" no flow ({FLOW_NONE}); a new flow ({FLOW_NEW});" - f" or a specific flow (e.g. 2). The default is {FLOW_ALL}." - " Reuse the option to assign multiple specific flows." - ) - - parser.add_option( - "--meta", metavar="DESCRIPTION", action="store", - dest="flow_descr", default=None, - help=f"description of triggered flow (with --flow={FLOW_NEW})." - ) - - parser.add_option( - "--wait", action="store_true", default=False, dest="flow_wait", - help="Wait for merge with current active flows before flowing on." - ) - + add_flow_opts(parser) return parser @@ -137,11 +116,7 @@ async def run(options: 'Values', workflow_id: str, *tokens_list): @cli_function(get_option_parser) def main(parser: COP, options: 'Values', *ids: str): """CLI for "cylc trigger".""" - - if options.flow is None: - options.flow = [FLOW_ALL] # default to all active flows validate_flow_opts(options) - call_multi( partial(run, options), *ids,