romm_cli/commands/
platforms.rs1use anyhow::Result;
2use clap::{Args, Subcommand};
3
4use crate::client::RommClient;
5use crate::commands::print::print_platforms_table;
6use crate::commands::OutputFormat;
7use crate::services::PlatformService;
8
9#[derive(Args, Debug)]
11pub struct PlatformsCommand {
12 #[command(subcommand)]
13 pub action: Option<PlatformsAction>,
14
15 #[arg(long, global = true)]
17 pub json: bool,
18}
19
20#[derive(Subcommand, Debug)]
22pub enum PlatformsAction {
23 #[command(visible_alias = "ls")]
25 List,
26 #[command(visible_alias = "info")]
28 Get {
29 id: u64,
31 },
32}
33
34pub async fn handle(
35 cmd: PlatformsCommand,
36 client: &RommClient,
37 format: OutputFormat,
38) -> Result<()> {
39 let action = cmd.action.unwrap_or(PlatformsAction::List);
40
41 let service = PlatformService::new(client);
42 match action {
43 PlatformsAction::List => {
44 let platforms = service.list_platforms().await?;
45
46 match format {
47 OutputFormat::Json => {
48 println!("{}", serde_json::to_string_pretty(&platforms)?);
49 }
50 OutputFormat::Text => {
51 print_platforms_table(&platforms);
52 }
53 }
54 }
55 PlatformsAction::Get { id } => {
56 let platform = service.get_platform(id).await?;
57
58 match format {
59 OutputFormat::Json => {
60 println!("{}", serde_json::to_string_pretty(&platform)?);
61 }
62 OutputFormat::Text => {
63 println!("{}", serde_json::to_string_pretty(&platform)?);
64 }
65 }
66 }
67 }
68
69 Ok(())
70}