ggen-cli-lib 26.6.11

CLI interface for ggen
Documentation
//! Describe artifact handler
//! Verb: describe | Noun: artifact/specification

use crate::commands::paas::errors::Result;
use std::path::Path;

/// Describe an artifact or resource
pub async fn describe_resource(name: &str, detailed: bool, format: &str) -> Result<()> {
    println!("📄 Resource Description");
    println!("======================");
    println!("Name: {}", name);
    println!("Format: {}", format);
    println!("Detailed: {}", if detailed { "yes" } else { "no" });
    println!();

    // Check if resource exists as a file
    let path = Path::new(name);
    if path.exists() {
        let metadata = path.metadata().map_err(|e| {
            crate::commands::paas::errors::PaasError::IoError(format!("Failed to read metadata: {}", e))
        })?;

        println!("Type: {}", if path.is_dir() { "Directory" } else { "File" });
        println!("Size: {} bytes", metadata.len());

        if detailed {
            println!("Permissions: {:?}", metadata.permissions());
            println!("Modified: {:?}", metadata.modified());

            if path.is_file() {
                if let Ok(ext) = path.extension() {
                    println!("Extension: {}", ext.to_string_lossy());
                }
            }
        }
    } else {
        // Try to describe as a known resource type
        match name {
            "paas.toml" | "ggen-paas.toml" => {
                println!("Type: Configuration File");
                println!("Description: PaaS deployment configuration");
                println!();
                println!("This file defines:");
                println!("  - Deployment environments");
                println!("  - Build artifacts");
                println!("  - Resource limits");
                println!("  - Environment variables");
            }
            "ggen-spec-kit" => {
                println!("Type: Git Submodule");
                println!("Description: ggen specification kit templates");
                println!();
                println!("Contains:");
                println!("  - RDF ontology templates");
                println!("  - CLI schema definitions");
                println!("  - Code generation templates");
            }
            "clap-noun-verb" => {
                println!("Type: Git Submodule");
                println!("Description: Noun-verb CLI framework");
                println!();
                println!("Provides:");
                println!("  - Semantic CLI structure");
                println!("  - Command routing");
                println!("  - Help generation");
            }
            _ => {
                println!("Type: Unknown Resource");
                println!();
                println!("⚠️  Resource '{}' not found in local filesystem", name);
                println!();
                println!("Available resources:");
                println!("  - paas.toml (configuration)");
                println!("  - ggen-spec-kit (submodule)");
                println!("  - clap-noun-verb (submodule)");
                println!("  - .specify/ (specifications)");
            }
        }
    }

    Ok(())
}

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

    #[tokio::test]
    async fn test_describe_default_format() {
        let result = describe_resource("test-artifact", false, "table").await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_describe_json_format() {
        let result = describe_resource("test", true, "json").await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_describe_known_resource() {
        let result = describe_resource("paas.toml", false, "table").await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_describe_submodule() {
        let result = describe_resource("ggen-spec-kit", true, "table").await;
        assert!(result.is_ok());
    }
}