refactor: give every command we run a type of its own

This commit is contained in:
2026-09-08 11:54:21 +00:00
parent 3d06f7dcb0
commit d7626d9f5e
16 changed files with 968 additions and 324 deletions

92
src/cmd/compose.rs Normal file
View File

@@ -0,0 +1,92 @@
use super::{Argv, Cmd};
fn compose() -> Argv {
Argv::new("docker").arg("compose")
}
// docker compose run --rm, which runs the image's entrypoint and so fixes up the
// container user before handing over
pub struct Run {
service: String,
inner: Argv,
}
impl Run {
pub fn wrapping(service: &str, inner: Argv) -> Self {
Self {
service: service.to_string(),
inner,
}
}
}
impl Cmd for Run {
fn argv(&self) -> Argv {
compose()
.arg("run")
.arg("--rm")
.arg(&self.service)
.args(self.inner.words())
}
}
// the merged project file, with every extends and env_file resolved
pub struct Config;
impl Cmd for Config {
fn argv(&self) -> Argv {
compose().arg("config").flag("--format", "json")
}
}
// the container id a service is running as, empty when it is not running
pub struct Ps {
service: String,
}
impl Ps {
pub fn id_of(service: &str) -> Self {
Self {
service: service.to_string(),
}
}
}
impl Cmd for Ps {
fn argv(&self) -> Argv {
compose().arg("ps").arg("--quiet").arg(&self.service)
}
}
pub struct Up;
impl Cmd for Up {
fn argv(&self) -> Argv {
compose().arg("up").arg("--detach")
}
}
pub struct Start {
service: String,
}
impl Start {
pub fn service(service: &str) -> Self {
Self {
service: service.to_string(),
}
}
}
impl Cmd for Start {
fn argv(&self) -> Argv {
compose().arg("start").arg(&self.service)
}
}
pub struct Stop;
impl Cmd for Stop {
fn argv(&self) -> Argv {
compose().arg("stop")
}
}