Skip to main content

cqlite_cli/repl/commands/
schema.rs

1//! :schema list meta-command implementation
2
3use anyhow::Result;
4use colored::Colorize;
5use std::path::PathBuf;
6
7/// Execute the :schema list command
8///
9/// Displays loaded schema file paths with a simple numbered list.
10/// Shows helpful hint when no schemas are loaded.
11///
12/// # Arguments
13///
14/// * `schema_paths` - Reference to the list of currently loaded schema file paths
15///
16/// # Returns
17///
18/// Returns Ok(()) on success, or an error if display operations fail
19pub async fn execute_schema_list(schema_paths: &[PathBuf]) -> Result<()> {
20    println!("{}", "=== Loaded Schemas ===".green().bold());
21    println!();
22
23    if schema_paths.is_empty() {
24        println!("{}", "No schemas loaded".yellow());
25        println!(
26            "{}",
27            "Hint: Use :schema load <path> to load schemas".dimmed()
28        );
29        return Ok(());
30    }
31
32    println!("Schema files ({}):", schema_paths.len());
33    for (i, path) in schema_paths.iter().enumerate() {
34        println!("  {}. {}", i + 1, path.display().to_string().green());
35    }
36    println!();
37
38    Ok(())
39}