//! Handler for `mcptest cache <subcommand>`.

use anyhow::Result;

use crate::cli::args::{CacheArgs, CacheCommand};
use crate::commands;

/// Translate the clap-derived [`CacheArgs`] into the plain
/// [`commands::CacheRunArgs`] consumed by the cache command and
/// dispatch.
pub(crate) fn cache_command(args: CacheArgs) -> Result<i32> {
    let sub = match args.command {
        CacheCommand::List => commands::CacheSubcommand::List,
        CacheCommand::Stats => commands::CacheSubcommand::Stats,
        CacheCommand::Clear { older_than } => commands::CacheSubcommand::Clear { older_than },
        CacheCommand::Prune => commands::CacheSubcommand::Prune,
    };
    commands::run_cache(commands::CacheRunArgs {
        command: sub,
        cache_dir: args.cache_dir,
    })
}
