pub mod new;
pub mod make;
pub mod serve;
pub mod db;
pub mod migrate;
pub mod seed;
pub mod route;
pub mod cache;
pub mod queue;
pub mod config;
pub mod test;
pub mod build;
pub mod deploy;
pub mod info;
pub mod package;
pub mod dev;
pub use crate::{
DbCommands, MakeCommands, MigrateCommands, RouteCommands,
CacheCommands, QueueCommands, ConfigCommands,
PackageCommands, DevCommands
};
use anyhow::Result;
use colored::*;
use std::process::Command;
pub struct CommandUtils;
impl CommandUtils {
pub fn is_rustisan_project() -> bool {
std::path::Path::new("Cargo.toml").exists() &&
std::path::Path::new("rustisan.toml").exists()
}
pub fn ensure_rustisan_project() -> Result<()> {
if !Self::is_rustisan_project() {
anyhow::bail!("This command must be run from within a Rustisan project directory");
}
Ok(())
}
pub fn execute_command(cmd: &str, args: &[&str]) -> Result<()> {
let output = Command::new(cmd)
.args(args)
.output()?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("Command failed: {}", stderr);
}
Ok(())
}
pub fn success(message: &str) {
println!("{} {}", "✓".green().bold(), message);
}
pub fn info(message: &str) {
println!("{} {}", "ℹ".blue().bold(), message);
}
pub fn warning(message: &str) {
println!("{} {}", "⚠".yellow().bold(), message);
}
pub fn error(message: &str) {
eprintln!("{} {}", "✗".red().bold(), message);
}
pub fn ensure_directory(path: &std::path::Path) -> Result<()> {
if !path.exists() {
std::fs::create_dir_all(path)?;
}
Ok(())
}
pub fn to_snake_case(input: &str) -> String {
let mut result = String::new();
for (i, ch) in input.chars().enumerate() {
if i > 0 && ch.is_uppercase() {
result.push('_');
}
result.push(ch.to_lowercase().next().unwrap_or(ch));
}
result
}
pub fn to_pascal_case(input: &str) -> String {
input
.split('_')
.map(|word| {
let mut chars = word.chars();
match chars.next() {
None => String::new(),
Some(first) => first.to_uppercase().collect::<String>() + &chars.as_str(),
}
})
.collect()
}
}