Skip to main content

romm_cli/frontend/
cli.rs

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