Skip to main content

cqlite_cli/repl/commands/
keyspaces.rs

1//! :keyspaces meta-command implementation
2use anyhow::Result;
3use colored::Colorize;
4use std::path::Path;
5
6#[cfg(feature = "state_machine")]
7use cqlite_core::discovery::DiscoveryService;
8
9pub async fn execute_keyspaces(data_dir: Option<&Path>) -> Result<()> {
10    #[cfg(not(feature = "state_machine"))]
11    {
12        let _ = data_dir;
13        return Err(anyhow::anyhow!(
14            "Keyspaces command requires state_machine feature. Rebuild with --features state_machine"
15        ));
16    }
17
18    #[cfg(feature = "state_machine")]
19    {
20        let Some(data_dir) = data_dir else {
21            return Err(anyhow::anyhow!(
22                "Data directory not configured. Use :config data-dir <PATH>"
23            ));
24        };
25
26        let discovery_service = DiscoveryService::new(data_dir.to_path_buf(), None);
27        let summary = discovery_service.scan().await?;
28
29        println!("{}", "=== Keyspaces ===".green().bold());
30        println!();
31
32        if summary.keyspaces.is_empty() {
33            println!("{}", "No keyspaces found".yellow());
34        } else {
35            println!("Found {} keyspace(s):", summary.keyspaces.len());
36            for keyspace in &summary.keyspaces {
37                println!("  - {}", keyspace.yellow().bold());
38            }
39        }
40        println!();
41
42        Ok(())
43    }
44}