mod build_cmd;
mod global_config;
mod new_cmd;
mod setup;
mod sync_plugin;
mod templates;
use std::path::{Path, PathBuf};
use clap::{Parser, Subcommand};
use rusteal_codegen::config::find_project_root;
#[derive(Parser)]
#[command(name = "rusteal", about = "Rusteal CLI — Rust for Unreal Engine")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
New {
name: String,
#[arg(long, default_value = ".")]
dir: PathBuf,
#[arg(long)]
runtime_path: Option<PathBuf>,
#[arg(long)]
no_build: bool,
},
Setup {
project: PathBuf,
},
Build {
project: Option<PathBuf>,
#[arg(long)]
step: Option<u8>,
#[arg(long, default_value_t = 1)]
from: u8,
},
Generate {
project: Option<PathBuf>,
},
SyncPlugin,
}
fn main() {
let cli = Cli::parse();
match cli.command {
Commands::New { name, dir, runtime_path, no_build } => {
let engine = global_config::engine_path();
new_cmd::run_new(&new_cmd::NewOptions {
name: &name,
parent: &dir,
engine: &engine,
runtime_path: runtime_path.as_deref(),
build: !no_build,
});
}
Commands::Setup { project } => {
let engine = global_config::engine_path();
setup::run_setup(&project, &engine);
}
Commands::Build { project, step, from } => {
let root = project_root(project.as_deref());
let engine = global_config::engine_path();
build_cmd::run_build(&root, &engine, step, from);
}
Commands::Generate { project } => {
let root = project_root(project.as_deref());
rusteal_codegen::run_generate(&root);
}
Commands::SyncPlugin => {
sync_plugin::run_sync();
}
}
}
fn project_root(given: Option<&Path>) -> PathBuf {
let start = given
.map(Path::to_path_buf)
.unwrap_or_else(|| std::env::current_dir().expect("current directory"));
find_project_root(&start).unwrap_or_else(|| {
eprintln!(
"Error: no .uproject in {} or its parents. Pass the project directory.",
start.display()
);
std::process::exit(1);
})
}