1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use anyhow::Result;
use clap::ValueEnum;
use crate::podman::Podman;
/// List running Compose projects
#[derive(clap::Args, Debug)]
#[command(next_display_order = None)]
pub(crate) struct Args {
/// Format the output
#[arg(long, value_enum, default_value_t = Format::Table)]
format: Format,
/// Only display IDs
#[arg(short, long)]
quiet: bool,
/// Filter output based on conditions provided
#[arg(long)]
filter: Vec<String>,
/// Show all stopped Compose projects
#[arg(short, long)]
all: bool,
}
#[derive(ValueEnum, PartialEq, Clone, Debug)]
enum Format {
Table,
Json,
}
pub(crate) async fn run(args: Args, podman: &Podman) -> Result<()> {
if args.quiet {
print!(
"{}",
podman
.run(
[
"pod",
"ps",
"--quiet",
"--filter",
"label=io.podman.compose.project"
]
.into_iter()
.chain(args.filter.iter().flat_map(|filter| ["--filter", filter]))
.chain(if args.all {
vec![]
} else {
vec!["--filter", "status=running"]
})
)
.await?
);
} else {
print!(
"{}",
podman
.run(
["pod", "ps", "--filter", "label=io.podman.compose.project"]
.into_iter()
.chain([
"--format",
match args.format {
Format::Table =>
"table {{.Name}} {{.Status}} {{.Created}} {{.NumberOfContainers}}",
Format::Json => "json",
}
])
.chain(args.filter.iter().flat_map(|filter| ["--filter", filter]))
.chain(if args.all {
vec![]
} else {
vec!["--filter", "status=running"]
})
)
.await?
);
}
Ok(())
}