Skip to content

Commit

Permalink
[IMP] "docker compose ps" argument services (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuentes73 authored Nov 17, 2022
1 parent 7dc3102 commit db488b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python_on_whales/components/compose/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,18 @@ def port(
host, port = str(result).split(":")
return host, int(port)

def ps(self) -> List[python_on_whales.components.container.cli_wrapper.Container]:
def ps(
self,
services: Optional[List[str]] = None,
) -> List[python_on_whales.components.container.cli_wrapper.Container]:
"""Returns the containers that were created by the current project.
# Returns
A `List[python_on_whales.Container]`
"""
full_cmd = self.docker_compose_cmd + ["ps", "--quiet"]
if services:
full_cmd += services
result = run(full_cmd)
ids = result.splitlines()
# The first line might be a warning for experimental
Expand Down
3 changes: 3 additions & 0 deletions tests/python_on_whales/components/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ def test_docker_compose_ps():
containers = docker.compose.ps()
names = set(x.name for x in containers)
assert names == {"components_my_service_1", "components_busybox_1"}
containers = docker.compose.ps(["my_service"])
names = set(x.name for x in containers)
assert names == {"components_my_service_1"}
docker.compose.down()


Expand Down

0 comments on commit db488b7

Please sign in to comment.