1use anyhow::{anyhow, Result};
2
3use crate::client::RommClient;
4use crate::commands::{api, auth, cache, download, platforms, roms, scan, Commands, OutputFormat};
5use crate::core::interrupt::InterruptContext;
6
7pub async fn run(command: Commands, client: &RommClient, global_json: bool) -> Result<()> {
9 match command {
10 Commands::Api(cmd) => {
11 let format = OutputFormat::from_flags(global_json, false);
12 api::handle(cmd, client, format).await
13 }
14 Commands::Platforms(cmd) => {
15 let format = OutputFormat::from_flags(global_json, cmd.json);
16 platforms::handle(cmd, client, format).await
17 }
18 Commands::Roms(cmd) => {
19 let format = OutputFormat::from_flags(global_json, cmd.json);
20 roms::handle(*cmd, client, format).await
21 }
22 Commands::Scan(cmd) => {
23 let format = OutputFormat::from_flags(global_json, false);
24 let interrupt = InterruptContext::new();
25 scan::handle(cmd, client, format, Some(interrupt)).await
26 }
27 Commands::Download(cmd) => {
28 let interrupt = InterruptContext::new();
29 download::handle(cmd, client, Some(interrupt)).await
30 }
31 Commands::Cache(cmd) => cache::handle(cmd),
32 Commands::Auth(cmd) => {
33 let format = OutputFormat::from_flags(global_json, false);
34 auth::handle(cmd, client, format).await
35 }
36 Commands::Init(_) => Err(anyhow!(
37 "internal routing error: init command in CLI frontend"
38 )),
39 Commands::Tui { .. } => Err(anyhow!(
40 "internal routing error: TUI command in CLI frontend"
41 )),
42 Commands::Update => {
43 let interrupt = InterruptContext::new();
44 crate::commands::update::handle(Some(interrupt)).await
45 }
46 }
47}