From 8530fbdad2c86110c06c835ead86c0c075b75fc1 Mon Sep 17 00:00:00 2001 From: LooLzzz Date: Tue, 21 May 2024 21:45:42 +0300 Subject: [PATCH] Allow list of str in `DockerContainerListFilters['filters']` and `format_dict_for_cli()` --- .../components/container/cli_wrapper.py | 2 +- python_on_whales/utils.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/python_on_whales/components/container/cli_wrapper.py b/python_on_whales/components/container/cli_wrapper.py index 81ffc35b..5d7a8c82 100644 --- a/python_on_whales/components/container/cli_wrapper.py +++ b/python_on_whales/components/container/cli_wrapper.py @@ -58,7 +58,7 @@ { "id": str, "name": str, - "label": str, + "label": Union[str, List[str]], "exited": int, "status": Literal[ "created", "restarting", "running", "removing", "paused", "exited", "dead" diff --git a/python_on_whales/utils.py b/python_on_whales/utils.py index 7643adfe..75effaef 100644 --- a/python_on_whales/utils.py +++ b/python_on_whales/utils.py @@ -295,8 +295,21 @@ def stream_stdout_and_stderr( raise DockerException(full_cmd, exit_code, stderr=full_stderr) -def format_dict_for_cli(dictionary: Dict[str, str], separator="="): - return [f"{key}{separator}{value}" for key, value in dictionary.items()] +def format_dict_for_cli(dictionary: Dict[str, Union[str, List[str]]], separator="=") -> List[str]: + result_list = [] + + for key, value in dictionary.items(): + if isinstance(value, str): + result_list.append( + f"{key}{separator}{value}" + ) + elif isinstance(value, (list, tuple)): + result_list.extend( + f"{key}{separator}{v}" + for v in value + ) + + return result_list def read_env_file(env_file: Path) -> Dict[str, str]: