A comprehensive command-line toolkit for DevOps automation, featuring multi-cloud deployment, log analysis, system monitoring, and infrastructure management with blazing-fast performance.
This CLI toolkit showcases Rust's excellence in building performant command-line applications. Designed for DevOps engineers, it provides a unified interface for managing cloud infrastructure, analyzing logs, monitoring systems, and automating deployment pipelines. The tool demonstrates Rust's ability to create user-friendly CLIs with minimal overhead and maximum reliability.
use clap::{Parser, Subcommand};
use colored::*;
use anyhow::Result;
#[derive(Parser)]
#[command(name = "devops")]
#[command(about = "A comprehensive DevOps toolkit", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, global = true)]
verbose: bool,
}
#[derive(Subcommand)]
enum Commands {
Deploy {
#[arg(short, long)]
environment: String,
#[arg(short, long)]
config: std::path::PathBuf,
},
Logs {
#[arg(short, long)]
service: String,
#[arg(short, long, default_value = "100")]
lines: usize,
#[arg(short, long)]
follow: bool,
},
Monitor {
#[command(subcommand)]
resource: MonitorCommands,
},
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Deploy { environment, config } => {
println!("{}", "🚀 Starting deployment...".green().bold());
deploy::execute(environment, config).await?
}
Commands::Logs { service, lines, follow } => {
logs::analyze(service, lines, follow).await?
}
Commands::Monitor { resource } => {
monitor::watch(resource).await?
}
}
Ok(())
}
use regex::Regex;
use std::collections::HashMap;
pub async fn analyze(service: String, lines: usize, follow: bool) -> Result<()> {
let error_pattern = Regex::new(r"ERROR|FATAL|CRITICAL")?;
let mut error_count = HashMap::new();
let logs = fetch_logs(&service, lines).await?;
for line in logs {
if error_pattern.is_match(&line) {
let error_type = extract_error_type(&line);
*error_count.entry(error_type).or_insert(0) += 1;
}
// Colorize output based on log level
let colored_line = match detect_level(&line) {
LogLevel::Error => line.red(),
LogLevel::Warning => line.yellow(),
LogLevel::Info => line.blue(),
_ => line.normal(),
};
println!("{}", colored_line);
}
// Display statistics
println!("\n{}", "📊 Log Analysis Summary:".cyan().bold());
for (error, count) in error_count {
println!(" {} {}: {}", "â–¸".yellow(), error, count);
}
Ok(())
}
This project represents my passion for building blazingly fast command-line tools with minimal resource usage. It showcases my ability to create reliable DevOps automation tools that engineers can depend on for critical infrastructure tasks. If you have questions or wish to collaborate on a project, please reach out via the Contact section.
Let's build something great together.
Best regards,
Damilare Lekan Adekeye