Skip to main content

romm_cli/commands/
scan.rs

1//! Top-level `scan` command: trigger RomM `scan_library` without uploading.
2
3use std::time::Duration;
4
5use anyhow::Result;
6use clap::Args;
7
8use crate::client::RommClient;
9
10use super::library_scan::{run_scan_library_flow, ScanCacheInvalidate, ScanLibraryOptions};
11use super::OutputFormat;
12
13#[derive(Args, Debug)]
14pub struct ScanCommand {
15    /// Wait until the scan task completes (polls every 2 seconds)
16    #[arg(long)]
17    pub wait: bool,
18
19    /// Max seconds to wait when `--wait` is set (default: 3600)
20    #[arg(long, requires = "wait")]
21    pub wait_timeout_secs: Option<u64>,
22}
23
24pub async fn handle(cmd: ScanCommand, client: &RommClient, format: OutputFormat) -> Result<()> {
25    let options = ScanLibraryOptions {
26        wait: cmd.wait,
27        wait_timeout: Duration::from_secs(cmd.wait_timeout_secs.unwrap_or(3600)),
28        cache_invalidate: if cmd.wait {
29            ScanCacheInvalidate::AllPlatforms
30        } else {
31            ScanCacheInvalidate::None
32        },
33    };
34    run_scan_library_flow(client, options, format).await
35}