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
mod audit;
mod codegen;
mod components;
mod feasibility;
mod manifest;
mod next;
mod route_parity;
use std::path::PathBuf;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
/// Port Laravel PHP apps to a new Laravel runtime (Laravel Rust today) and check nothing was lost.
#[derive(Parser)]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
/// Inventory a Laravel PHP app (read-only) into inventory.json.
Audit {
/// Path to the Laravel PHP app.
app: PathBuf,
/// Where to write the inventory. Never inside the PHP app.
#[arg(long, default_value = "inventory.json")]
out: PathBuf,
/// Command that runs PHP in the app directory, e.g. "php" or
/// "docker run --rm -v $PWD:/app -w /app php:8.3-cli php".
#[arg(long, default_value = "php")]
php: String,
},
/// Score every inventory item green / yellow / red and print the report.
Feasibility {
#[arg(default_value = "inventory.json")]
inventory: PathBuf,
},
/// Write PORTING.md: the porting checklist in dependency order (keeps ticked items).
Manifest {
#[arg(default_value = "inventory.json")]
inventory: PathBuf,
/// Where to write the checklist. Never inside the PHP app.
#[arg(long, default_value = "PORTING.md")]
out: PathBuf,
},
/// Write models, policies, factories, migrations, input structs, handler stubs, routes and Jinja views into a Laravel Rust app.
/// Never overwrites; PORT-TODO marks what's left; wiring steps go to larakiln-codegen.md.
Codegen {
#[arg(default_value = "inventory.json")]
inventory: PathBuf,
/// The Laravel Rust app (from `laravel new <name> --rust`).
#[arg(long)]
rust: PathBuf,
},
/// Print the first unticked PORTING.md item: its PHP source, its generated Rust stub and PORT-TODOs,
/// the reference to read, and when it counts as done.
Next {
#[arg(default_value = "PORTING.md")]
porting: PathBuf,
#[arg(long, default_value = "inventory.json")]
inventory: PathBuf,
/// The Laravel Rust app, to find the stub `larakiln codegen` wrote for the item.
#[arg(long)]
rust: Option<PathBuf>,
},
/// Check every PHP route has a Rust route (method + URI) with the same auth. Exits 1 on gaps.
RouteParity {
#[arg(default_value = "inventory.json")]
inventory: PathBuf,
/// The Laravel Rust app; runs `<rust-cmd> route:list --json` there.
#[arg(long, required_unless_present = "rust_routes", conflicts_with = "rust_routes")]
rust: Option<PathBuf>,
/// Command that runs the Rust app's console, e.g. "laravel".
#[arg(long, default_value = "cargo run -q --")]
rust_cmd: String,
/// Saved output of the Rust app's `route:list --json`, instead of --rust.
#[arg(long)]
rust_routes: Option<PathBuf>,
/// URI prefix kept in PHP on purpose (path split), e.g. --ignore /admin. Repeatable.
#[arg(long)]
ignore: Vec<String>,
},
}
fn main() -> ExitCode {
let result = match Cli::parse().command {
Command::Audit { app, out, php } => audit::run(&app, &out, &php).map(|()| true),
Command::Feasibility { inventory } => feasibility::run(&inventory).map(|()| true),
Command::Manifest { inventory, out } => manifest::run(&inventory, &out).map(|()| true),
Command::Codegen { inventory, rust } => codegen::run(&inventory, &rust).map(|()| true),
Command::Next { porting, inventory, rust } => next::run(&porting, &inventory, rust.as_deref()).map(|()| true),
Command::RouteParity { inventory, rust, rust_cmd, rust_routes, ignore } => route_parity::run(
&inventory,
route_parity::Rust { dir: rust.as_deref(), cmd: &rust_cmd, routes: rust_routes.as_deref() },
&ignore,
),
};
match result {
Ok(true) => ExitCode::SUCCESS,
Ok(false) => ExitCode::from(1),
Err(e) => {
eprintln!("larakiln: {e}");
ExitCode::FAILURE
}
}
}