From 80a36d1fca023ed57e2d7aee745e36e067ad1f92 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Thu, 23 Apr 2026 07:49:07 -0400 Subject: [PATCH] simplify: pass CommandContext to runs archive/rm helpers `run_bulk` and `remove_from` took separate `json: bool` + `printer` parameters. Thread the context through instead and pull json/printer out of it inside the helper. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../fabro-cli/src/commands/runs/archive.rs | 31 +++++-------------- lib/crates/fabro-cli/src/commands/runs/rm.rs | 19 ++++-------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/lib/crates/fabro-cli/src/commands/runs/archive.rs b/lib/crates/fabro-cli/src/commands/runs/archive.rs index 7d1f2239a..bf9543392 100644 --- a/lib/crates/fabro-cli/src/commands/runs/archive.rs +++ b/lib/crates/fabro-cli/src/commands/runs/archive.rs @@ -3,7 +3,6 @@ use anyhow::{Result, bail}; use super::short_run_id; use crate::args::{RunsArchiveArgs, RunsUnarchiveArgs}; use crate::command_context::CommandContext; -use crate::server_client; use crate::shared::print_json_pretty; pub(crate) async fn archive_command( @@ -11,14 +10,7 @@ pub(crate) async fn archive_command( base_ctx: &CommandContext, ) -> Result<()> { let ctx = base_ctx.with_target(&args.server)?; - run_bulk( - Action::Archive, - &args.runs, - ctx.server().await?.as_ref(), - ctx.json_output(), - ctx.printer(), - ) - .await + run_bulk(Action::Archive, &args.runs, &ctx).await } pub(crate) async fn unarchive_command( @@ -26,14 +18,7 @@ pub(crate) async fn unarchive_command( base_ctx: &CommandContext, ) -> Result<()> { let ctx = base_ctx.with_target(&args.server)?; - run_bulk( - Action::Unarchive, - &args.runs, - ctx.server().await?.as_ref(), - ctx.json_output(), - ctx.printer(), - ) - .await + run_bulk(Action::Unarchive, &args.runs, &ctx).await } #[derive(Clone, Copy)] @@ -55,13 +40,11 @@ impl Action { } } -async fn run_bulk( - action: Action, - identifiers: &[String], - client: &server_client::Client, - json: bool, - printer: fabro_util::printer::Printer, -) -> Result<()> { +async fn run_bulk(action: Action, identifiers: &[String], ctx: &CommandContext) -> Result<()> { + let client = ctx.server().await?; + let client = client.as_ref(); + let json = ctx.json_output(); + let printer = ctx.printer(); let mut had_errors = false; let mut changed = Vec::new(); let mut errors = Vec::new(); diff --git a/lib/crates/fabro-cli/src/commands/runs/rm.rs b/lib/crates/fabro-cli/src/commands/runs/rm.rs index 362d1a5c1..31cacfd99 100644 --- a/lib/crates/fabro-cli/src/commands/runs/rm.rs +++ b/lib/crates/fabro-cli/src/commands/runs/rm.rs @@ -8,21 +8,14 @@ use crate::shared::print_json_pretty; pub(crate) async fn remove_command(args: &RunsRemoveArgs, base_ctx: &CommandContext) -> Result<()> { let ctx = base_ctx.with_target(&args.server)?; - remove_from( - args, - ctx.server().await?.as_ref(), - ctx.json_output(), - ctx.printer(), - ) - .await + remove_from(args, &ctx).await } -async fn remove_from( - args: &RunsRemoveArgs, - client: &server_client::Client, - json: bool, - printer: fabro_util::printer::Printer, -) -> Result<()> { +async fn remove_from(args: &RunsRemoveArgs, ctx: &CommandContext) -> Result<()> { + let client = ctx.server().await?; + let client = client.as_ref(); + let json = ctx.json_output(); + let printer = ctx.printer(); let mut had_errors = false; let mut removed = Vec::new(); let mut errors = Vec::new();