diff --git a/src/molecule/config.py b/src/molecule/config.py index 35aa5dd68c..1e56ebdf3a 100644 --- a/src/molecule/config.py +++ b/src/molecule/config.py @@ -281,7 +281,7 @@ def collection(self) -> CollectionData | None: LOG.warning( "The detected galaxy.yml file (%s) is incomplete, missing %s", galaxy_file, - missing_keys, + util.oxford_comma(missing_keys), ) return None diff --git a/src/molecule/util.py b/src/molecule/util.py index a57abc61ea..3e97446f90 100644 --- a/src/molecule/util.py +++ b/src/molecule/util.py @@ -597,3 +597,22 @@ def print_as_yaml(data: object) -> None: # https://github.com/Textualize/rich/discussions/990#discussioncomment-342217 result = Syntax(code=safe_dump(data), lexer="yaml", background_color="default") console.print(result) + + +def oxford_comma(listed: Iterable[bool | str | Path], condition: str = "and") -> str: + """Format a list into a sentence. + + :param listed: List of string entries to modify + :param condition: String to splice into string, usually 'and' + :returns: Modified string + """ + match [f"'{entry!s}'" for entry in listed]: + case []: + return "" + case [one]: + return one + case [one, two]: + return f"{one} {condition} {two}" + + listed = list(listed) + return f"{', '.join(str(x) for x in listed[:-1])}, {condition} {listed[-1]}"