Skip to main content

romm_cli/frontend/
cli.rs

1use anyhow::{anyhow, Result};
2
3use crate::client::RommClient;
4use crate::commands::{api, cache, download, platforms, roms, Commands, OutputFormat};
5
6/// Execute one non-TUI CLI command.
7pub async fn run(command: Commands, client: &RommClient, global_json: bool) -> Result<()> {
8    match command {
9        Commands::Api(cmd) => {
10            let format = OutputFormat::from_flags(global_json, false);
11            api::handle(cmd, client, format).await
12        }
13        Commands::Platforms(cmd) => {
14            let format = OutputFormat::from_flags(global_json, cmd.json);
15            platforms::handle(cmd, client, format).await
16        }
17        Commands::Roms(cmd) => {
18            let format = OutputFormat::from_flags(global_json, cmd.json);
19            roms::handle(cmd, client, format).await
20        }
21        Commands::Download(cmd) => download::handle(cmd, client).await,
22        Commands::Cache(cmd) => cache::handle(cmd),
23        Commands::Init(_) => Err(anyhow!(
24            "internal routing error: init command in CLI frontend"
25        )),
26        Commands::Tui => Err(anyhow!(
27            "internal routing error: TUI command in CLI frontend"
28        )),
29        Commands::Update => crate::commands::update::handle(),
30    }
31}