mirror of
https://github.com/containers/podman-compose.git
synced 2025-05-17 04:30:59 +02:00
Merge pull request #716 from Tayeh/images_cmd
add `podman-compose images` command
This commit is contained in:
commit
58641f0545
@ -2851,6 +2851,42 @@ async def compose_stats(compose, args):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cmd_run(podman_compose, "images", "List images used by the created containers")
|
||||||
|
async def compose_images(compose, args):
|
||||||
|
img_containers = [cnt for cnt in compose.containers if "image" in cnt]
|
||||||
|
data = []
|
||||||
|
if args.quiet is True:
|
||||||
|
for img in img_containers:
|
||||||
|
name = img["name"]
|
||||||
|
output = await compose.podman.output([], "images", ["--quiet", img["image"]])
|
||||||
|
data.append(output.decode("utf-8").split())
|
||||||
|
else:
|
||||||
|
data.append(["CONTAINER", "REPOSITORY", "TAG", "IMAGE ID", "SIZE", ""])
|
||||||
|
for img in img_containers:
|
||||||
|
name = img["name"]
|
||||||
|
output = await compose.podman.output(
|
||||||
|
[],
|
||||||
|
"images",
|
||||||
|
[
|
||||||
|
"--format",
|
||||||
|
"table " + name + " {{.Repository}} {{.Tag}} {{.ID}} {{.Size}}",
|
||||||
|
"-n",
|
||||||
|
img["image"],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
data.append(output.decode("utf-8").split())
|
||||||
|
|
||||||
|
# Determine the maximum length of each column
|
||||||
|
column_widths = [max(map(len, column)) for column in zip(*data)]
|
||||||
|
|
||||||
|
# Print each row
|
||||||
|
for row in data:
|
||||||
|
# Format each cell using the maximum column width
|
||||||
|
formatted_row = [cell.ljust(width) for cell, width in zip(row, column_widths)]
|
||||||
|
formatted_row[-2:] = ["".join(formatted_row[-2:]).strip()]
|
||||||
|
print("\t".join(formatted_row))
|
||||||
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# command arguments parsing
|
# command arguments parsing
|
||||||
###################
|
###################
|
||||||
@ -3285,6 +3321,11 @@ def compose_kill_parse(parser):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@cmd_parse(podman_compose, "images")
|
||||||
|
def compose_images_parse(parser):
|
||||||
|
parser.add_argument("-q", "--quiet", help="Only display images IDs", action="store_true")
|
||||||
|
|
||||||
|
|
||||||
@cmd_parse(podman_compose, ["stats"])
|
@cmd_parse(podman_compose, ["stats"])
|
||||||
def compose_stats_parse(parser):
|
def compose_stats_parse(parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
Loading…
Reference in New Issue
Block a user