1use clap::Subcommand;
8
9use crate::cli::{Session, emit, report};
10use crate::exit::ExitCode;
11use crate::render::{Format, machine, queue as render};
12
13#[derive(Debug, Subcommand)]
14pub enum ComponentCommand {
15 #[command(long_about = crate::cli::help::md(crate::cli::help::COMPONENT_LIST))]
17 List {
18 #[arg(long, short = 'q')]
20 queue: Option<String>,
21 },
22}
23
24pub async fn run(command: &ComponentCommand, session: &Session) -> ExitCode {
25 let client = match session.client() {
26 Ok(client) => client,
27 Err(code) => return code,
28 };
29
30 let ComponentCommand::List { queue } = command;
31 match client.components(queue.as_deref()).await {
32 Ok(components) => {
33 let rendered = match session.render.format {
34 Format::Text => Ok(render::components(
35 &components,
36 queue.as_deref(),
37 &session.render,
38 )),
39 Format::JsonRaw => machine(&components, Format::Json),
40 other => machine(&components, other),
41 };
42 match rendered {
43 Ok(text) => {
44 emit(&text);
45 ExitCode::Success
46 }
47 Err(error) => report(&error, ExitCode::Failure),
48 }
49 }
50 Err(error) => {
51 let code = error.exit_code();
52 report(&error, code)
53 }
54 }
55}