systemprompt_cli/commands/core/files/ai/
count.rs1use anyhow::Result;
7use clap::Args;
8use systemprompt_files::FileRepository;
9use systemprompt_identifiers::UserId;
10
11use crate::commands::core::files::types::AiFilesCountOutput;
12use crate::context::CommandContext;
13use crate::shared::CommandOutput;
14
15#[derive(Debug, Clone, Args)]
16pub struct CountArgs {
17 #[arg(
18 long,
19 help = "Filter by user ID (optional, counts all if not specified)"
20 )]
21 pub user: Option<String>,
22}
23
24pub async fn execute(args: CountArgs, ctx: &CommandContext) -> Result<CommandOutput> {
25 let app = ctx.app_context().await?;
26 let service = FileRepository::new(app.db_pool())?;
27
28 let user_id = args.user.as_ref().map(|u| UserId::new(u.clone()));
29
30 let count = match &user_id {
31 Some(uid) => service.count_ai_images_by_user(uid).await?,
32 None => service.count_ai_images().await?,
33 };
34
35 let output = AiFilesCountOutput { count, user_id };
36
37 Ok(CommandOutput::card_value("AI Images Count", &output))
38}