rustisan 0.0.1

Command-line interface for the Rustisan web framework
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
//! Rustisan CLI - Command-line interface for the Rustisan web framework
//!
//! This CLI provides Laravel-like commands for Rustisan applications.

use clap::{Parser, Subcommand};
use colored::*;
// Mock rustisan-core module for testing
mod rustisan_core {
    pub fn init_logging() {
        // Mock implementation
    }
    pub const VERSION: &str = "0.1.1";
}

use rustisan_core::{init_logging, VERSION};
use std::process;

mod commands;
mod generators;
mod utils;

use commands::*;

/// Rustisan CLI - A Laravel-inspired web framework for Rust
#[derive(Parser)]
#[command(name = "rustisan")]
#[command(version = VERSION)]
#[command(about = "A Laravel-inspired web framework for Rust")]
#[command(long_about = "Rustisan CLI provides commands for creating, managing, and deploying Rustisan applications.")]
struct Cli {
    #[command(subcommand)]
    command: Commands,

    /// Enable verbose output
    #[arg(short, long, global = true)]
    verbose: bool,

    /// Suppress output
    #[arg(short, long, global = true)]
    quiet: bool,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Create a new Rustisan application
    New {
        /// Name of the application
        name: String,
        /// Directory to create the application in
        #[arg(short, long)]
        path: Option<String>,
        /// Use a specific template
        #[arg(short, long)]
        template: Option<String>,
        /// Initialize git repository
        #[arg(long, default_value = "true")]
        git: bool,
    },

    /// Generate application components
    Make {
        #[command(subcommand)]
        component: MakeCommands,
    },

    /// Serve the application
    Serve {
        /// Host to bind to
        #[arg(short, long, default_value = "127.0.0.1")]
        host: String,
        /// Port to bind to
        #[arg(short, long, default_value = "3000")]
        port: u16,
        /// Environment to run in
        #[arg(short, long, default_value = "development")]
        env: String,
        /// Enable hot reload
        #[arg(long)]
        reload: bool,
    },

    /// Database operations
    Db {
        #[command(subcommand)]
        operation: DbCommands,
    },

    /// Migration operations
    Migrate {
        #[command(subcommand)]
        operation: Option<MigrateCommands>,
    },

    /// Seeder operations
    Seed {
        /// Specific seeder to run
        #[arg(short, long)]
        class: Option<String>,
        /// Force seeding in production
        #[arg(long)]
        force: bool,
    },

    /// Route operations
    Route {
        #[command(subcommand)]
        operation: RouteCommands,
    },

    /// Cache operations
    Cache {
        #[command(subcommand)]
        operation: CacheCommands,
    },

    /// Queue operations
    Queue {
        #[command(subcommand)]
        operation: QueueCommands,
    },

    /// Configuration operations
    Config {
        #[command(subcommand)]
        operation: ConfigCommands,
    },

    /// Run tests
    Test {
        /// Specific test file or pattern
        pattern: Option<String>,
        /// Run only unit tests
        #[arg(long)]
        unit: bool,
        /// Run only integration tests
        #[arg(long)]
        integration: bool,
        /// Show test output
        #[arg(long)]
        verbose: bool,
    },

    /// Build the application for production
    Build {
        /// Target environment
        #[arg(short, long, default_value = "production")]
        env: String,
        /// Enable optimizations
        #[arg(long)]
        optimize: bool,
        /// Output directory
        #[arg(short, long)]
        output: Option<String>,
    },

    /// Deploy the application
    Deploy {
        /// Deployment target
        target: Option<String>,
        /// Skip build step
        #[arg(long)]
        skip_build: bool,
        /// Dry run (show what would be deployed)
        #[arg(long)]
        dry_run: bool,
    },

    /// Show application information
    Info {
        /// Show detailed information
        #[arg(long)]
        detailed: bool,
    },



    /// Package management
    Package {
        #[command(subcommand)]
        operation: PackageCommands,
    },

    /// Development tools
    Dev {
        #[command(subcommand)]
        tool: DevCommands,
    },
}

#[derive(Subcommand)]
pub enum MakeCommands {
    /// Generate a controller
    Controller {
        /// Controller name
        name: String,
        /// Generate a resource controller
        #[arg(short, long)]
        resource: bool,
        /// Generate an API controller
        #[arg(long)]
        api: bool,
        /// Generate with model
        #[arg(short, long)]
        model: Option<String>,
    },

    /// Generate a model
    Model {
        /// Model name
        name: String,
        /// Generate migration
        #[arg(short, long)]
        migration: bool,
        /// Generate factory
        #[arg(short, long)]
        factory: bool,
        /// Generate seeder
        #[arg(short, long)]
        seeder: bool,
    },

    /// Generate a migration
    Migration {
        /// Migration name
        name: String,
        /// Create table migration
        #[arg(long)]
        create: Option<String>,
        /// Modify table migration
        #[arg(long)]
        table: Option<String>,
    },

    /// Generate middleware
    Middleware {
        /// Middleware name
        name: String,
    },

    /// Generate a request validator
    Request {
        /// Request name
        name: String,
    },

    /// Generate a resource transformer
    Resource {
        /// Resource name
        name: String,
        /// Generate collection resource
        #[arg(short, long)]
        collection: bool,
    },

    /// Generate a seeder
    Seeder {
        /// Seeder name
        name: String,
        /// Associated model
        #[arg(short, long)]
        model: Option<String>,
    },

    /// Generate a factory
    Factory {
        /// Factory name
        name: String,
        /// Associated model
        #[arg(short, long)]
        model: Option<String>,
    },

    /// Generate a command
    Command {
        /// Command name
        name: String,
    },

    /// Generate a job
    Job {
        /// Job name
        name: String,
        /// Synchronous job
        #[arg(long)]
        sync: bool,
    },

    /// Generate an event
    Event {
        /// Event name
        name: String,
    },

    /// Generate a listener
    Listener {
        /// Listener name
        name: String,
        /// Associated event
        #[arg(short, long)]
        event: Option<String>,
    },

    /// Generate a policy
    Policy {
        /// Policy name
        name: String,
        /// Associated model
        #[arg(short, long)]
        model: Option<String>,
    },

    /// Generate a trait
    Trait {
        /// Trait name
        name: String,
    },

    /// Generate a test
    Test {
        /// Test name
        name: String,
        /// Unit test
        #[arg(short, long)]
        unit: bool,
        /// Integration test
        #[arg(long)]
        integration: bool,
    },
}

#[derive(Subcommand)]
pub enum DbCommands {
    /// Show database status
    Status,
    /// Create database
    Create,
    /// Drop database
    Drop {
        #[arg(long)]
        force: bool,
    },
    /// Reset database
    Reset {
        #[arg(long)]
        force: bool,
    },
    /// Seed database
    Seed,
}

#[derive(Subcommand)]
pub enum MigrateCommands {
    /// Run pending migrations
    Up,
    /// Rollback migrations
    Down {
        /// Number of migrations to rollback
        #[arg(short, long, default_value = "1")]
        steps: u32,
    },
    /// Reset all migrations
    Reset,
    /// Rollback and re-run migrations
    Refresh,
    /// Show migration status
    Status,
    /// Create a new migration
    Make {
        name: String,
    },
}

#[derive(Subcommand)]
pub enum RouteCommands {
    /// List all routes
    List {
        /// Filter by method
        #[arg(short, long)]
        method: Option<String>,
        /// Filter by name
        #[arg(short, long)]
        name: Option<String>,
        /// Show middleware
        #[arg(long)]
        middleware: bool,
    },
    /// Clear route cache
    Clear,
    /// Cache routes
    Cache,
}

#[derive(Subcommand)]
pub enum CacheCommands {
    /// Clear all cache
    Clear,
    /// Clear specific cache store
    Forget {
        key: String,
    },
    /// Cache configuration
    Config,
}

#[derive(Subcommand)]
pub enum QueueCommands {
    /// Start queue worker
    Work {
        /// Queue name
        #[arg(short, long)]
        queue: Option<String>,
        /// Number of jobs to process
        #[arg(long)]
        max_jobs: Option<u32>,
        /// Memory limit in MB
        #[arg(long)]
        memory: Option<u32>,
        /// Sleep time when no jobs
        #[arg(long, default_value = "3")]
        sleep: u64,
    },
    /// Restart queue workers
    Restart,
    /// Show failed jobs
    Failed,
    /// Retry failed jobs
    Retry {
        /// Job ID to retry
        id: Option<String>,
    },
    /// Flush failed jobs
    Flush,
}

#[derive(Subcommand)]
pub enum ConfigCommands {
    /// Show all configuration values
    Show,
    /// Get a specific configuration value
    Get {
        /// Configuration key (e.g., app.name, database.default)
        key: String,
    },
    /// Set configuration value
    Set {
        /// Configuration key (e.g., app.name, database.default)
        key: String,
        /// Configuration value
        value: String,
    },
    /// Generate application key
    GenerateKey,
    /// Validate configuration
    Validate,
    /// Reset configuration to defaults
    Reset,
}



#[derive(Subcommand)]
pub enum PackageCommands {
    /// Install a package
    Install {
        name: String,
        /// Package version
        #[arg(short, long)]
        version: Option<String>,
    },
    /// Remove a package
    Remove {
        name: String,
    },
    /// List installed packages
    List,
    /// Update packages
    Update,
}

#[derive(Subcommand)]
pub enum DevCommands {
    /// Start development server with hot reload
    Server {
        #[arg(short, long, default_value = "127.0.0.1")]
        host: String,
        #[arg(short, long, default_value = "3000")]
        port: u16,
    },
    /// Watch files for changes
    Watch,
    /// Format code
    Format,
    /// Check code with clippy
    Check,
    /// Generate documentation
    Docs {
        #[arg(long)]
        open: bool,
    },
}

#[tokio::main]
async fn main() {
    let cli = Cli::parse();

    // Initialize logging based on verbosity
    if !cli.quiet {
        init_logging();
    }

    // Print banner unless quiet
    if !cli.quiet {
        print_banner();
    }

    let result = match cli.command {
        Commands::New { name, path, template, git } => {
            commands::new::handle(name, path, template, git).await
        }
        Commands::Make { component } => {
            commands::make::handle(component).await
        }
        Commands::Serve { host, port, env, reload } => {
            commands::serve::handle(host, port, env, reload).await
        }
        Commands::Db { operation } => {
            commands::db::handle(operation).await
        }
        Commands::Migrate { operation } => {
            commands::migrate::handle(operation).await
        }
        Commands::Seed { class, force } => {
            commands::seed::handle(class, force).await
        }
        Commands::Route { operation } => {
            commands::route::handle(operation).await
        }
        Commands::Cache { operation } => {
            commands::cache::handle(operation).await
        }
        Commands::Queue { operation } => {
            commands::queue::handle(operation).await
        }
        Commands::Config { operation } => {
            commands::config::handle(operation).await
        }
        Commands::Test { pattern, unit, integration, verbose } => {
            commands::test::handle(pattern, unit, integration, verbose).await
        }
        Commands::Build { env, optimize, output } => {
            commands::build::handle(env, optimize, output).await
        }
        Commands::Deploy { target, skip_build, dry_run } => {
            commands::deploy::handle(target, skip_build, dry_run).await
        }
        Commands::Info { detailed } => {
            commands::info::handle(detailed).await
        }

        Commands::Package { operation } => {
            commands::package::handle(operation).await
        }
        Commands::Dev { tool } => {
            commands::dev::handle(tool).await
        }
    };

    if let Err(e) = result {
        eprintln!("{} {}", "Error:".red().bold(), e);
        process::exit(1);
    }
}

fn print_banner() {
    println!("{}", "
██████╗ ██╗   ██╗███████╗████████╗██╗███████╗ █████╗ ███╗   ██╗
██╔══██╗██║   ██║██╔════╝╚══██╔══╝██║██╔════╝██╔══██╗████╗  ██║
██████╔╝██║   ██║███████╗   ██║   ██║███████╗███████║██╔██╗ ██║
██╔══██╗██║   ██║╚════██║   ██║   ██║╚════██║██╔══██║██║╚██╗██║
██║  ██║╚██████╔╝███████║   ██║   ██║███████║██║  ██║██║ ╚████║
╚═╝  ╚═╝ ╚═════╝ ╚══════╝   ╚═╝   ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═══╝
".cyan().bold());

    println!("{} {}", "Rustisan CLI".green().bold(), format!("v{}", VERSION).dimmed());
    println!("{}\n", "A Laravel-inspired web framework for Rust".dimmed());
}