diff --git a/crates/cli/src/commands/sbx/image/ls.rs b/crates/cli/src/commands/sbx/image/ls.rs index 5169964c..6f4bb667 100644 --- a/crates/cli/src/commands/sbx/image/ls.rs +++ b/crates/cli/src/commands/sbx/image/ls.rs @@ -4,12 +4,17 @@ use crate::auth::context::CliContext; use crate::error::Result; use crate::output::table::new_table; -pub async fn run(ctx: &CliContext) -> Result<()> { +pub async fn run(ctx: &CliContext, output_json: bool) -> Result<()> { let (base_url, _, _) = super::templates_base_url(ctx)?; let client = ctx.client()?; let items = super::list_all_images(ctx, &client, &base_url).await?; + if output_json { + println!("{}", serde_json::to_string_pretty(&items)?); + return Ok(()); + } + if items.is_empty() { println!("No images found."); return Ok(()); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 206925e6..8918d5d6 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -653,7 +653,11 @@ enum ImageCommands { }, /// List all sandbox images - Ls, + Ls { + /// Print the sandbox image list as JSON to stdout + #[arg(long = "json", hide = true)] + json: bool, + }, /// Show details for a sandbox image Describe { @@ -1145,7 +1149,9 @@ async fn run_command(ctx: &mut CliContext, command: Commands) -> error::Result<( ) .await } - ImageCommands::Ls => commands::sbx::image::ls::run(ctx).await, + ImageCommands::Ls { json } => { + commands::sbx::image::ls::run(ctx, json).await + } ImageCommands::Describe { name_or_id } => { commands::sbx::image::describe::run(ctx, &name_or_id).await }