added ppc server and mize run external subcommands

This commit is contained in:
Sebastian Moser
2026-09-30 09:37:21 +02:00
parent e96e93a5a0
commit c19de1ed84
9 changed files with 497 additions and 55 deletions

View File

@@ -9,8 +9,9 @@ use std::process::exit;
use mize::error::{MizeError, MizeResult};
use mize::item::ItemData;
use mize::platform::os::config_from_cli_args;
use mize::platform::os::logging::init_logger;
use mize::{instance, Mize};
use mize::{Mize, instance, mize_err};
use std::env;
use std::io::Write;
use std::sync::Arc;
@@ -21,37 +22,72 @@ mod cli;
static APPNAME: &str = "mize";
macro_rules! compile_in_parts {
(
$mize:ident,
$(
$name:literal : $part:path
),+ $(,)?
) => {
let enable = $mize.get_config("enable")?;
let mut enable_str = Vec::new();
for name in enable.cbor().as_array().ok_or(mize_err!("config(enable) not a list"))? {
enable_str.push(name.as_text().ok_or("part name not a str")?);
}
$(
if enable_str.contains(&$name) {
tracing::info!("enabling compiled_in_part: {}", $name);
$part(&mut $mize);
}
)+
};
}
fn main() {
// welcome to the mize source code
// this is the main entry point for platforms with an os (eg: Linux, MacOS, Windows, BSD, ...)
// Also let's try to make the most best documented code ever. (eventually) so it's fun to work on
if let Err(e) = tried_main() {
e.log();
}
}
fn tried_main() -> MizeResult<()> {
let cli_matches = cli_matches();
// logging
init_logger(&cli_matches);
// match command
let result = match cli_matches.subcommand() {
Some(("run", sub_matches)) => cli::run(sub_matches),
Some(("status", sub_matches)) => cli::status(sub_matches),
Some(("info", sub_matches)) => cli::info(sub_matches),
// init mize
let mut mize = Mize::with_config(config_from_cli_args(&cli_matches)?)?;
// compiled in parts (which for now is all)
compile_in_parts! {
mize,
"cli": marts::cli,
"auth": marts::part_client_auth,
"spacetime": marts::spacetime,
//"matrix": marts::part_matrix,
"ppc.server": marts::ppc::server::part_ppc_server,
"c2vi": marts::part_c2vi,
};
// match subcommand
match cli_matches.subcommand() {
Some(("run", sub_matches)) => cli::run(sub_matches, &mut mize),
Some(("status", sub_matches)) => cli::status(sub_matches, &mut mize),
Some(("info", sub_matches)) => cli::info(sub_matches, &mut mize),
Some(("get", sub_matches)) => cli::get(sub_matches),
Some(("set", sub_matches)) => cli::set(sub_matches),
Some(("show", sub_matches)) => cli::show(sub_matches),
Some(("call", sub_matches)) => cli::call(sub_matches),
Some(("create", sub_matches)) => cli::create(sub_matches),
Some(("format-cbor", sub_matches)) => cli::format_cbor(sub_matches),
Some(("get", sub_matches)) => cli::get(sub_matches, &mut mize),
Some(("set", sub_matches)) => cli::set(sub_matches, &mut mize),
Some(("show", sub_matches)) => cli::show(sub_matches, &mut mize),
Some(("call", sub_matches)) => cli::call(sub_matches, &mut mize),
Some(("create", sub_matches)) => cli::create(sub_matches, &mut mize),
Some(("format-cbor", sub_matches)) => cli::format_cbor(sub_matches, &mut mize),
Some((cmd, sub_matches)) => cli::run_from_part(cmd, sub_matches),
Some((cmd, sub_matches)) => cli::run_from_part(cmd, sub_matches, &mut mize),
None => Err(MizeError::new()
.msg("No subcommand was passed. use --help to list availavle comamnds.")),
};
}?;
if let Err(err) = result {
err.log();
exit(1);
}
Ok(())
}
fn cli_matches() -> clap::ArgMatches {
@@ -119,7 +155,7 @@ fn cli_matches() -> clap::ArgMatches {
.subcommand(Command::new("call").aliases(["c"]))
.subcommand(Command::new("create").aliases(["cr"]))
.subcommand(Command::new("status").aliases(["st"]))
.subcommand(Command::new("run"))
.subcommand(Command::new("run").allow_external_subcommands(true))
.subcommand(Command::new("format-cbor").aliases(["fc"]))
.arg_required_else_help(true);