The same lexer-based splitter as S12b, now with explicit re-exports: every moved free fn comes back to its module under its old name and old visibility (cfg attributes carried), so a name can never clash with another glob import. 162 module files of leleka-runtime (68), cuda-driver (84), deploy (10), cpu-sys, igpu and leleka-memory are split into groups of about 250 lines; types, constants, macros, nested modules and tests stay. Not touched: the files kar-off-ab edits, crate roots (lib.rs, main.rs, bin/*), and giant single impl blocks (next). This changes codegen-unit placement of engine code, so it is covered by the bitwise replay and the paired A/B on the 5090, not by a binary comparison.
65 lines
2.8 KiB
Rust
65 lines
2.8 KiB
Rust
//! Moved out of the parent module by STRA-338: fn parse.
|
|
|
|
#[allow(unused_imports)]
|
|
use super::*;
|
|
|
|
pub fn parse(args: &[String], env: &Environment) -> Result<Command, String> {
|
|
let Some((command, rest)) = args.split_first() else {
|
|
return Ok(Command::Help);
|
|
};
|
|
match command.as_str() {
|
|
"-h" | "--help" | "help" => Ok(Command::Help),
|
|
"version" | "--version" | "-V" => Ok(Command::Version),
|
|
"up" => up_options(rest, env).map(Command::Up),
|
|
"preflight" => up_options(rest, env).map(Command::Preflight),
|
|
"status" => up_options(rest, env).map(Command::Status),
|
|
"down" => up_options(rest, env).map(Command::Down),
|
|
"reconfigure" => reconfigure_command(rest, env),
|
|
"verify" => up_options(rest, env).map(Command::Verify),
|
|
"logs" => logs_command(rest, env),
|
|
"report" => report_command(rest, env),
|
|
"profiles" => match rest {
|
|
[] => Ok(Command::Profiles(None)),
|
|
[show, name] if show == "show" => Ok(Command::Profiles(Some(name.clone()))),
|
|
_ => Err("usage: leleka profiles [show NAME]".into()),
|
|
},
|
|
"run" => {
|
|
let flags = parse_flags(rest, &[("--config", true), ("--kar-fd", true)])?;
|
|
let config = text(&flags, "--config").ok_or("leleka run needs --config FILE")?;
|
|
Ok(Command::Run {
|
|
config: PathBuf::from(config),
|
|
kar_fd: flags
|
|
.get("--kar-fd")
|
|
.map(|_| number(&flags, "--kar-fd", 0u32))
|
|
.transpose()?,
|
|
})
|
|
}
|
|
"service" => {
|
|
let Some((action, rest)) = rest.split_first() else {
|
|
return Err("usage: leleka service install|uninstall|status|start|stop".into());
|
|
};
|
|
let action = match action.as_str() {
|
|
"install" => ServiceAction::Install,
|
|
"uninstall" => ServiceAction::Uninstall,
|
|
"status" => ServiceAction::Status,
|
|
"start" => ServiceAction::Start,
|
|
"stop" => ServiceAction::Stop,
|
|
"hold" => ServiceAction::Hold,
|
|
other => {
|
|
return Err(format!(
|
|
"unknown service action {other:?}; use install, uninstall, status, start or stop"
|
|
));
|
|
}
|
|
};
|
|
up_options(rest, env).map(|options| Command::Service(action, options))
|
|
}
|
|
"exec-inherit" => Ok(Command::ExecInherit(rest.to_vec())),
|
|
"seal-exec" => Ok(Command::SealExec(rest.to_vec())),
|
|
"seal-probe" => match rest {
|
|
[file] if !file.starts_with("--") => Ok(Command::SealProbe(PathBuf::from(file))),
|
|
_ => Err("usage: leleka seal-probe FILE".into()),
|
|
},
|
|
other => Err(format!("unknown command {other:?}; see `leleka --help`")),
|
|
}
|
|
}
|