systemprompt-cli 0.2.1

Unified CLI for systemprompt.io AI governance: agent orchestration, MCP governance, analytics, profiles, cloud deploy, and self-hosted operations.
Documentation
use anyhow::{Result, anyhow};
use clap::Args;
use systemprompt_runtime::AppContext;
use systemprompt_users::BannedIpRepository;

use crate::CliConfig;
use crate::commands::admin::users::types::BanCleanupOutput;
use crate::shared::CommandResult;

#[derive(Debug, Clone, Copy, Args)]
pub struct CleanupArgs {
    #[arg(short = 'y', long)]
    pub yes: bool,
}

pub async fn execute(
    args: CleanupArgs,
    _config: &CliConfig,
) -> Result<CommandResult<BanCleanupOutput>> {
    let ctx = AppContext::new().await?;
    let ban_repository = BannedIpRepository::new(ctx.db_pool())?;

    if !args.yes {
        return Err(anyhow!(
            "This will delete all expired bans. Use --yes to confirm."
        ));
    }

    let cleaned = ban_repository.cleanup_expired().await?;

    let output = BanCleanupOutput {
        cleaned,
        message: format!("Cleaned up {} expired ban(s)", cleaned),
    };

    Ok(CommandResult::text(output).with_title("Ban Cleanup"))
}