Skip to content

Commit

Permalink
Centralize cli flow options.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Aug 13, 2023
1 parent 5d279ec commit 69334f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 55 deletions.
25 changes: 25 additions & 0 deletions cylc/flow/flow_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
30 changes: 2 additions & 28 deletions cylc/flow/scripts/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
29 changes: 2 additions & 27 deletions cylc/flow/scripts/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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


Expand All @@ -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,
Expand Down

0 comments on commit 69334f5

Please sign in to comment.