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::{analyze_project, ProjectAnalysis};
40pub use error::{IaCGeneratorError, Result};
41pub use generator::{generate_dockerfile, generate_compose, generate_terraform};
42pub use handlers::*;
43use cli::Commands;
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 { path, json, detailed, display, only } => {
51            match handlers::handle_analyze(path, json, detailed, display, only) {
52                Ok(_output) => Ok(()), // The output was already printed by display_analysis_with_return
53                Err(e) => Err(e),
54            }
55        }
56        Commands::Generate {
57            path,
58            output,
59            dockerfile,
60            compose,
61            terraform,
62            all,
63            dry_run,
64            force
65        } => {
66            handlers::handle_generate(path, output, dockerfile, compose, terraform, all, dry_run, force)
67        }
68        Commands::Validate { path, types, fix } => {
69            handlers::handle_validate(path, types, fix)
70        }
71        Commands::Support { languages, frameworks, detailed } => {
72            handlers::handle_support(languages, frameworks, detailed)
73        }
74        Commands::Dependencies { path, licenses, vulnerabilities, prod_only, dev_only, format } => {
75            handlers::handle_dependencies(path, licenses, vulnerabilities, prod_only, dev_only, format).await.map(|_| ())
76        }
77        Commands::Vulnerabilities { path, severity, format, output } => {
78            handlers::handle_vulnerabilities(path, severity, format, output).await
79        }
80        Commands::Security {
81            path,
82            mode,
83            include_low,
84            no_secrets,
85            no_code_patterns,
86            no_infrastructure,
87            no_compliance,
88            frameworks,
89            format,
90            output,
91            fail_on_findings
92        } => {
93            handlers::handle_security(
94                path,
95                mode,
96                include_low,
97                no_secrets,
98                no_code_patterns,
99                no_infrastructure,
100                no_compliance,
101                frameworks,
102                format,
103                output,
104                fail_on_findings
105            ).map(|_| ()) // Map Result<String> to Result<()>
106        }
107        Commands::Tools { command } => {
108            handlers::handle_tools(command).await
109        }
110    }
111}