/// Command-line interface for detector functionality
///
/// Provides two main commands:
/// - `detect`: Analyze a project to detect technologies and infer requirements
/// - `complete`: Complete an infrastructure declaration with inferred
///   requirements
pub mod commands;

use clap::{Parser, Subcommand};
pub use commands::{CompleteCommand, DetectCommand};

/// Infrastructure-from-Code Detector CLI
///
/// Detects project technologies, infers infrastructure requirements,
/// and completes incomplete declarations.
#[derive(Parser, Debug)]
#[command(name = "provisioning-detector")]
#[command(about = "Detect and complete infrastructure specifications", long_about = None)]
#[command(version = "0.1.0")]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Detect technologies and infer requirements in a project
    Detect(DetectCommand),

    /// Complete an infrastructure declaration with inferred requirements
    Complete(CompleteCommand),
}

impl Cli {
    /// Run the CLI
    pub fn run() -> anyhow::Result<()> {
        let cli = Self::parse();
        cli.execute()
    }

    fn execute(&self) -> anyhow::Result<()> {
        match &self.command {
            Commands::Detect(cmd) => cmd.execute(),
            Commands::Complete(cmd) => cmd.execute(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_cli_parse_detect() {
        let args = vec!["cli", "detect", "/path/to/project"];
        let cli = Cli::try_parse_from(args);
        assert!(cli.is_ok());
    }

    #[test]
    fn test_cli_parse_complete() {
        let args = vec!["cli", "complete", "/path/to/project"];
        let cli = Cli::try_parse_from(args);
        assert!(cli.is_ok());
    }
}
