1pub mod scaffolding;
2pub mod database;
3pub mod monitoring;
4pub mod builder;
5pub mod utils;
6pub mod auth;
7
8pub use scaffolding::*;
9pub use database::*;
10pub use monitoring::*;
11pub use builder::*;
12pub use utils::*;
13pub use auth::*;
14
15use std::env;
16use dotenvy::dotenv;
17use colored::*;
18use std::future::Future;
19use std::pin::Pin;
20
21pub type AsyncHook = Box<dyn Fn() -> Pin<Box<dyn Future<Output = ()>>>>;
22
23pub async fn run_cli<F, G>(migrate_fn: F, seed_fn: G)
24where
25 F: Fn(String) -> Pin<Box<dyn Future<Output = Result<(), String>>>>,
26 G: Fn() -> Pin<Box<dyn Future<Output = ()>>>
27{
28 let args: Vec<String> = env::args().collect();
29
30 if args.len() < 2 {
31 print_help();
32 return;
33 }
34
35 let command = &args[1];
36
37 if command != "new" {
39 let _ = dotenv();
40 }
41
42 match command.as_str() {
43 "migrate" | "migrate:refresh" | "migrate:back" | "migrate:rollback" => {
44 match migrate_fn(command.clone()).await {
45 Ok(_) => println!("\n{} Operasi '{}' berhasil.", "✅".green(), command),
46 Err(e) => eprintln!("\n{} Gagal: {}", "❌".red(), e),
47 }
48 }
49 "db:seed" => {
50 println!("{}", "🌱 Menjalankan seeder database...".cyan());
51 seed_fn().await;
52 println!("\n{} Database seeding berhasil.", "✅".green());
53 }
54 _ => {
55 }
58 }
59}
60
61pub fn print_help() {
62 println!("\n{}", "🛠️ RustBasic CLI".magenta().bold());
63 println!("{}", "=================".magenta());
64 println!("Gunakan 'rustbasic --help' untuk daftar perintah lengkap.");
65}