Skip to main content

systemprompt_cli/commands/admin/config/
list.rs

1use clap::Args;
2
3use super::types::{ConfigFileInfo, ConfigListOutput, ConfigSection, read_yaml_file};
4use crate::CliConfig;
5use crate::shared::CommandResult;
6
7#[derive(Debug, Clone, Copy, Args)]
8pub struct ListArgs {
9    #[arg(long, short = 'e')]
10    pub errors_only: bool,
11}
12
13pub fn execute(args: ListArgs, _config: &CliConfig) -> CommandResult<ConfigListOutput> {
14    let mut files = Vec::new();
15    let mut valid_count = 0;
16    let mut invalid_count = 0;
17
18    for section in ConfigSection::all() {
19        let section_files = match section.all_files() {
20            Ok(f) => f,
21            Err(e) => {
22                tracing::debug!(section = %section, error = %e, "Failed to list config files for section");
23                continue;
24            },
25        };
26
27        for file_path in section_files {
28            let exists = file_path.exists();
29            let (valid, error) = if exists {
30                match read_yaml_file(&file_path) {
31                    Ok(_) => (true, None),
32                    Err(e) => (false, Some(e.to_string())),
33                }
34            } else {
35                (false, Some("File not found".to_string()))
36            };
37
38            if valid {
39                valid_count += 1;
40            } else {
41                invalid_count += 1;
42            }
43
44            if args.errors_only && valid {
45                continue;
46            }
47
48            files.push(ConfigFileInfo {
49                path: file_path.display().to_string(),
50                section: section.to_string(),
51                exists,
52                valid,
53                error,
54            });
55        }
56    }
57
58    let output = ConfigListOutput {
59        total: valid_count + invalid_count,
60        valid: valid_count,
61        invalid: invalid_count,
62        files,
63    };
64
65    CommandResult::table(output).with_title("Configuration Files")
66}