Skip to main content

systemprompt_cli/commands/plugins/capabilities/
jobs.rs

1use clap::Args;
2
3use crate::CliConfig;
4use crate::commands::plugins::discover_registry;
5use crate::commands::plugins::types::{JobWithExtension, JobsListOutput};
6use crate::shared::CommandOutput;
7
8#[derive(Debug, Clone, Args)]
9pub struct JobsArgs {
10    #[arg(long, help = "Filter by extension ID")]
11    pub extension: Option<String>,
12
13    #[arg(long, help = "Show only enabled jobs")]
14    pub enabled: bool,
15}
16
17pub fn execute(args: &JobsArgs, _config: &CliConfig) -> CommandOutput {
18    let registry = discover_registry();
19
20    let jobs: Vec<JobWithExtension> = registry
21        .extensions()
22        .iter()
23        .filter(|ext| args.extension.as_ref().is_none_or(|f| ext.id().contains(f)))
24        .flat_map(|ext| {
25            ext.jobs()
26                .iter()
27                .filter_map(|job| {
28                    if args.enabled && !job.enabled() {
29                        return None;
30                    }
31
32                    Some(JobWithExtension {
33                        extension_id: systemprompt_identifiers::PluginId::new(ext.id()),
34                        extension_name: ext.name().to_owned(),
35                        job_name: job.name().to_owned(),
36                        schedule: job.schedule().to_owned(),
37                        enabled: job.enabled(),
38                    })
39                })
40                .collect::<Vec<_>>()
41        })
42        .collect();
43
44    let total = jobs.len();
45
46    let output = JobsListOutput { jobs, total };
47
48    CommandOutput::table_of(
49        vec!["extension_id", "job_name", "schedule", "enabled"],
50        &output.jobs,
51    )
52    .with_title("Jobs Across Extensions")
53}