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::endpoints::platforms::{GetPlatform, ListPlatforms};
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 match action {
42 PlatformsAction::List => {
43 let platforms = client.call(&ListPlatforms).await?;
44
45 match format {
46 OutputFormat::Json => {
47 println!("{}", serde_json::to_string_pretty(&platforms)?);
48 }
49 OutputFormat::Text => {
50 print_platforms_table(&platforms);
51 }
52 }
53 }
54 PlatformsAction::Get { id } => {
55 let platform = client.call(&GetPlatform { id }).await?;
56
57 match format {
58 OutputFormat::Json => {
59 println!("{}", serde_json::to_string_pretty(&platform)?);
60 }
61 OutputFormat::Text => {
62 println!("{}", serde_json::to_string_pretty(&platform)?);
63 }
64 }
65 }
66 }
67
68 Ok(())
69}