feat(template): do not print new lines if value of flag is None
All checks were successful
test / Linting (push) Successful in 37s
test / Molecule tests (default, ubuntu2004) (push) Successful in 50s
test / Molecule tests (default, debian11) (push) Successful in 1m22s
test / Molecule tests (default, debian12) (push) Successful in 1m23s
test / Molecule tests (with_custom_flags, debian11) (push) Successful in 34s
test / Molecule tests (with_custom_flags, debian12) (push) Successful in 32s
test / Molecule tests (default, ubuntu2204) (push) Successful in 59s
test / Molecule tests (with_custom_flags, ubuntu2204) (push) Successful in 53s
test / Molecule tests (with_custom_flags, ubuntu2004) (push) Successful in 59s

This commit is contained in:
Bertrand Lanson 2023-12-11 23:45:31 +01:00
parent 670cc6529f
commit 1d71409b22

View File

@ -1,9 +1,11 @@
# filter_plugins/docker_filters.py # filter_plugins/docker_filters.py
def create_docker_flags(flags): def create_docker_flags(flags):
if flags: if flags:
return "\n".join([create_docker_flag(item) for item in flags]) filtered_flags = [
create_docker_flag(item) for item in flags if create_docker_flag(item)
]
return "\n".join(filtered_flags)
return None return None
@ -11,14 +13,16 @@ def create_docker_flag(item):
if isinstance(item, dict): if isinstance(item, dict):
key = list(item.keys())[0] key = list(item.keys())[0]
value = item[key] value = item[key]
if isinstance(value, list): if value is not None:
return "\n".join(['--{} "{}" \\'.format(key, val) for val in value]) if isinstance(value, list):
else: flag_values = ['--{} "{}"'.format(key, val) for val in value]
return '--{} "{}" \\'.format(key, value) joined_values = " \\\n".join(flag_values)
return f"{joined_values} \\" if joined_values else None
else:
return '--{} "{}" \\'.format(key, value)
elif isinstance(item, str): elif isinstance(item, str):
return "--{} \\".format(item) return "--{} \\".format(item)
else: return None
return ""
class FilterModule(object): class FilterModule(object):