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