use mize::prelude::*; pub struct CliPart { id: MizeId } impl MizePart for CliPart { fn id(&self) -> MizeId { self.id.clone() } } impl CliPart { pub fn get(name: &str) -> MizeResult { let mut mize = get_global_mize()?; let part = mize.get_part(name)?; Ok(CliPart { id: part.id() }) } pub fn run(&self, cmdline: Vec) -> MizeResult<()> { let cmdline = cmdline.into_item_data(); let mut args = ItemData::new(); args.set_path("0", cmdline)?; dyn_call(self.id.clone(), "run", args)?; Ok(()) } pub fn set_command(&self, name: &str) -> MizeResult<()> { let name = name.into_item_data(); let mut args = ItemData::new(); args.set_path("0", name)?; dyn_call(self.id.clone(), "set_command", args)?; Ok(()) } pub fn subcommand MizeResult<()> + Send + Sync + 'static>(&self, subcmd: Command, action: T) -> MizeResult<()> { let mut subcmd_arg = ItemData::new(); subcmd_arg.set_path("_native", subcmd.native_id)?; let mut action_arg = ItemData::from_native(action)?; let mut args = ItemData::new(); args.set_path("0", subcmd_arg)?; args.set_path("1", action_arg)?; dyn_call(self.id.clone(), "subcommand", args)?; Ok(()) } } // the clap::Command native stuff pub struct Command { native_id: u32 } pub struct ArgMatches { native_id: u32 } pub struct Action { native_id: u32 } impl Command { pub fn new(name: &str) -> MizeResult { let name = name.into_item_data(); let mut args = ItemData::new(); args.set_path("0", name)?; let mut mize = get_global_mize()?; let id = mize.id_new_dots("cli.Command")?; let data = dyn_call(id.clone(), "new", args)?; let native_id: u32 = data.get_path("_native")?.native_take()?; Ok(Command { native_id }) } }