moving around complete

This commit is contained in:
Sebastian Moser
2026-02-15 14:14:18 +01:00
parent 691e695659
commit 0b7e54dc1d
103 changed files with 12 additions and 26 deletions

View File

@@ -1,41 +0,0 @@
use clap::{ArgMatches, Command};
use std::any::Any;
use std::collections::HashMap;
use mize::{Mize, MizePart, MizeResult, instance::MizePartGuard};
#[mize_part("cli")]
struct CliPart {
mize: Mize,
cmd: Option<Command>,
actions: HashMap<String, fn(&ArgMatches) -> MizeResult<()>>,
}
impl MizePart for CliPart {
fn init(&mut self, _mize: &mut Mize) -> MizeResult<()> {
Ok(())
}
fn run(&mut self, _mize: &mut Mize) -> MizeResult<()> {
let matches = self.cmd.take().unwrap().get_matches();
let sub_cmd = matches.subcommand_name().unwrap();
let action = self.actions.get(sub_cmd).unwrap();
action(matches.subcommand_matches(sub_cmd).unwrap());
Ok(())
}
fn opts(&self, mize: &mut Mize) {
mize.new_opt("cli.name");
}
}
impl CliPart {
pub fn subcommand(
&mut self,
cmd: Command,
action: fn(sub_matches: &ArgMatches) -> MizeResult<()>,
) -> &mut Command {
let cmd = self.cmd.take().unwrap().subcommand(cmd);
self.actions.insert(cmd.get_name().to_string(), action);
self.cmd = Some(cmd);
self.cmd.as_mut().unwrap()
}
}