used cli for prometeu runtime
This commit is contained in:
parent
0b2a97aa88
commit
28df72417b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1937,6 +1937,7 @@ dependencies = [
|
||||
name = "prometeu-runtime-desktop"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"cpal",
|
||||
"pixels",
|
||||
"prometeu-core",
|
||||
|
||||
@ -20,3 +20,4 @@ pixels = "0.15.0"
|
||||
cpal = "0.15.3"
|
||||
ringbuf = "0.4.7"
|
||||
serde_json = "1.0.149"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
@ -12,62 +12,49 @@ use runner::HostRunner;
|
||||
use cap::load_cap_config;
|
||||
use winit::event_loop::EventLoop;
|
||||
use prometeu_core::firmware::BootTarget;
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Cli {
|
||||
/// Run a cartridge
|
||||
#[arg(long, value_name = "PATH", conflicts_with = "debug")]
|
||||
run: Option<String>,
|
||||
|
||||
/// Debug a cartridge
|
||||
#[arg(long, value_name = "PATH", conflicts_with = "run")]
|
||||
debug: Option<String>,
|
||||
|
||||
/// Port for the debugger
|
||||
#[arg(long, default_value_t = 7777)]
|
||||
port: u16,
|
||||
|
||||
/// Root directory for the filesystem
|
||||
#[arg(long, value_name = "PATH")]
|
||||
fs_root: Option<String>,
|
||||
|
||||
/// Path to the capability configuration file
|
||||
#[arg(long, value_name = "PATH")]
|
||||
cap: Option<String>,
|
||||
}
|
||||
|
||||
pub fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let mut fs_root = None;
|
||||
let mut cap_config = None;
|
||||
let mut cartridge_path = None;
|
||||
let mut debug_mode = false;
|
||||
let mut debug_port = 7777;
|
||||
let cli = Cli::parse();
|
||||
|
||||
let mut i = 1; // Skip the executable name
|
||||
while i < args.len() {
|
||||
match args[i].as_str() {
|
||||
"--run" => {
|
||||
if i + 1 < args.len() {
|
||||
cartridge_path = Some(args[i + 1].clone());
|
||||
debug_mode = false;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
"--debug" => {
|
||||
if i + 1 < args.len() {
|
||||
cartridge_path = Some(args[i + 1].clone());
|
||||
debug_mode = true;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
"--port" => {
|
||||
if i + 1 < args.len() {
|
||||
if let Ok(port) = args[i + 1].parse::<u16>() {
|
||||
debug_port = port;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
"--fs-root" => {
|
||||
if i + 1 < args.len() {
|
||||
fs_root = Some(args[i + 1].clone());
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
"--cap" => {
|
||||
if i + 1 < args.len() {
|
||||
cap_config = load_cap_config(&args[i + 1]);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
let fs_root = cli.fs_root;
|
||||
let cap_config = cli.cap.as_ref().and_then(|path| load_cap_config(path));
|
||||
|
||||
let boot_target = if let Some(path) = cartridge_path {
|
||||
let boot_target = if let Some(path) = cli.debug {
|
||||
BootTarget::Cartridge {
|
||||
path,
|
||||
debug: debug_mode,
|
||||
debug_port: if debug_mode { debug_port } else { 7777 },
|
||||
debug: true,
|
||||
debug_port: cli.port,
|
||||
}
|
||||
} else if let Some(path) = cli.run {
|
||||
BootTarget::Cartridge {
|
||||
path,
|
||||
debug: false,
|
||||
debug_port: 7777,
|
||||
}
|
||||
} else {
|
||||
BootTarget::Hub
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user