syncable_cli/
lib.rs

1//! # Syncable IaC CLI
2//!
3//! A Rust-based command-line application that analyzes code repositories and automatically
4//! generates Infrastructure as Code configurations including Dockerfiles, Docker Compose
5//! files, and Terraform configurations.
6//!
7//! ## Features
8//!
9//! - **Language Detection**: Automatically detects programming languages and their versions
10//! - **Framework Analysis**: Identifies frameworks and libraries used in the project
11//! - **Smart Generation**: Creates optimized IaC configurations based on project analysis
12//! - **Multiple Formats**: Supports Docker, Docker Compose, and Terraform generation
13//! - **Security-First**: Generates secure configurations following best practices
14//!
15//! ## Example
16//!
17//! ```rust,no_run
18//! use syncable_cli::{analyze_project, generate_dockerfile};
19//! use std::path::Path;
20//!
21//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! let project_path = Path::new("./my-project");
23//! let analysis = analyze_project(project_path)?;
24//! let dockerfile = generate_dockerfile(&analysis)?;
25//! println!("{}", dockerfile);
26//! # Ok(())
27//! # }
28//! ```
29
30pub mod analyzer;
31pub mod cli;
32pub mod common;
33pub mod config;
34pub mod error;
35pub mod generator;
36pub mod handlers;
37
38// Re-export commonly used types and functions
39pub use analyzer::{ProjectAnalysis, analyze_project};
40use cli::Commands;
41pub use error::{IaCGeneratorError, Result};
42pub use generator::{generate_compose, generate_dockerfile, generate_terraform};
43pub use handlers::*;
44
45/// The current version of the CLI tool
46pub const VERSION: &str = env!("CARGO_PKG_VERSION");
47
48pub async fn run_command(command: Commands) -> Result<()> {
49    match command {
50        Commands::Analyze {
51            path,
52            json,
53            detailed,
54            display,
55            only,
56            color_scheme,
57        } => {
58            match handlers::handle_analyze(path, json, detailed, display, only, color_scheme) {
59                Ok(_output) => Ok(()), // The output was already printed by display_analysis_with_return
60                Err(e) => Err(e),
61            }
62        }
63        Commands::Generate {
64            path,
65            output,
66            dockerfile,
67            compose,
68            terraform,
69            all,
70            dry_run,
71            force,
72        } => handlers::handle_generate(
73            path, output, dockerfile, compose, terraform, all, dry_run, force,
74        ),
75        Commands::Validate { path, types, fix } => handlers::handle_validate(path, types, fix),
76        Commands::Support {
77            languages,
78            frameworks,
79            detailed,
80        } => handlers::handle_support(languages, frameworks, detailed),
81        Commands::Dependencies {
82            path,
83            licenses,
84            vulnerabilities,
85            prod_only,
86            dev_only,
87            format,
88        } => handlers::handle_dependencies(
89            path,
90            licenses,
91            vulnerabilities,
92            prod_only,
93            dev_only,
94            format,
95        )
96        .await
97        .map(|_| ()),
98        Commands::Vulnerabilities {
99            path,
100            severity,
101            format,
102            output,
103        } => handlers::handle_vulnerabilities(path, severity, format, output).await,
104        Commands::Security {
105            path,
106            mode,
107            include_low,
108            no_secrets,
109            no_code_patterns,
110            no_infrastructure,
111            no_compliance,
112            frameworks,
113            format,
114            output,
115            fail_on_findings,
116        } => {
117            handlers::handle_security(
118                path,
119                mode,
120                include_low,
121                no_secrets,
122                no_code_patterns,
123                no_infrastructure,
124                no_compliance,
125                frameworks,
126                format,
127                output,
128                fail_on_findings,
129            )
130            .map(|_| ()) // Map Result<String> to Result<()>
131        }
132        Commands::Tools { command } => handlers::handle_tools(command).await,
133    }
134}