refactor: put the dry-run and quiet checks on Ctx

This commit is contained in:
2026-09-09 12:32:55 +00:00
parent d9439253fd
commit b40dfe6124
10 changed files with 253 additions and 217 deletions

View File

@@ -1,4 +1,5 @@
use super::{Argv, Cmd};
use crate::ctx::Ctx;
// compose prints its own progress, which --quiet has to ask it to stop
fn compose(quiet: bool) -> Argv {
@@ -10,6 +11,49 @@ fn compose(quiet: bool) -> Argv {
}
}
// the compose commands, each already knowing whether -q asked compose to stop
// narrating. the flag was a field every construction site set by hand, and
// three of them did not, so `ahab -q` still had compose talking over the output
pub struct Compose<'a> {
ctx: &'a Ctx,
}
impl<'a> Compose<'a> {
pub(crate) fn new(ctx: &'a Ctx) -> Self {
Self { ctx }
}
pub fn up(&self) -> Up {
Up {
quiet: self.ctx.quiet,
}
}
pub fn stop(&self) -> Stop {
Stop {
quiet: self.ctx.quiet,
}
}
pub fn start(&self, service: &'a str) -> Start<'a> {
Start {
service,
quiet: self.ctx.quiet,
}
}
// reading the project says nothing, so there is no progress to quieten
pub fn config(&self) -> Config {
Config
}
pub fn ps(&self, service: &str) -> Ps {
Ps {
service: service.to_string(),
}
}
}
// docker compose run --rm, which runs the image's entrypoint and so fixes up the
// container user before handing over
pub struct Run {
@@ -19,20 +63,15 @@ pub struct Run {
}
impl Run {
pub fn wrapping(service: &str, inner: Argv) -> Self {
// only reached through Cmd::in_service, which takes the context, so the
// progress flag cannot be left off by forgetting a builder call
pub(super) fn wrapping(ctx: &Ctx, service: &str, inner: Argv) -> Self {
Self {
service: service.to_string(),
inner,
quiet: false,
quiet: ctx.quiet,
}
}
// compose narrates the container it creates before handing over, which is
// progress along the way rather than what was asked for
pub fn quiet(mut self, quiet: bool) -> Self {
self.quiet = quiet;
self
}
}
impl Cmd for Run {
@@ -59,14 +98,6 @@ 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(false).arg("ps").arg("--quiet").arg(&self.service)
@@ -74,7 +105,7 @@ impl Cmd for Ps {
}
pub struct Up {
pub quiet: bool,
quiet: bool,
}
impl Cmd for Up {
@@ -84,8 +115,8 @@ impl Cmd for Up {
}
pub struct Start<'a> {
pub service: &'a str,
pub quiet: bool,
service: &'a str,
quiet: bool,
}
impl Cmd for Start<'_> {
@@ -95,7 +126,7 @@ impl Cmd for Start<'_> {
}
pub struct Stop {
pub quiet: bool,
quiet: bool,
}
impl Cmd for Stop {