Skip to content

Commit

Permalink
Simplify the show --target parser argument
Browse files Browse the repository at this point in the history
  • Loading branch information
alarthast committed Jan 23, 2025
1 parent bbfccb7 commit 2004a71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions tests/workspace/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,16 @@ def test_website_repo_as_target():
MockReporter.assert_called_once_with("ebmdatalab/bennett.ox.ac.uk")


def test_list_of_orgs_as_target():
args = jobs.get_command_line_parser().parse_args(["show", "--target", "osc ebm"])
@pytest.mark.parametrize(
"cli_args",
[
["show", "--target", "osc ebm"],
["show", "--target", "osc ebm"],
["show", "--target", " osc ebm"],
],
)
def test_list_of_orgs_as_target(cli_args):
args = jobs.get_command_line_parser().parse_args(cli_args)
with patch("workspace.workflows.jobs.summarise_org") as mock_summarise_org:
jobs.main(args)
mock_summarise_org.assert_any_call("opensafely-core", False)
Expand Down
10 changes: 7 additions & 3 deletions workspace/workflows/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,19 @@ def get_usage_text(args) -> str:
def get_command_line_parser():
class SplitString(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
# Split space-separated strings into individual list items
setattr(namespace, self.dest, " ".join(values).split(" "))
setattr(namespace, self.dest, values.split())

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True)

# Main task: show workflows
show_parser = subparsers.add_parser("show")
show_parser.add_argument("--target", nargs="+", default=["all"], action=SplitString)
show_parser.add_argument(
"--target",
default="all",
action=SplitString,
help="Provide multiple targets as a space-separated quoted string, e.g. 'os osc'.",
)
show_parser.add_argument("--group", required=False)
show_parser.add_argument("--skip-successful", action="store_true", default=False)
show_parser.set_defaults(func=main)
Expand Down

0 comments on commit 2004a71

Please sign in to comment.