dyn calling works + vibed dioxus ui components + some mo provision prototyping
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use clap::{ArgMatches, Command};
|
||||
use mize::item::ItemData;
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, ffi::OsString};
|
||||
use mize::prelude::*;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
@@ -13,7 +13,6 @@ pub extern "C" fn part_cli() -> MizeResult<()> {
|
||||
|
||||
opt("state")
|
||||
.fun(Box::new(|| {
|
||||
println!("hiiiiii");
|
||||
let mize = get_global_mize().unwrap();
|
||||
let state = CliPartState {
|
||||
cmds: HashMap::new(),
|
||||
@@ -22,15 +21,13 @@ pub extern "C" fn part_cli() -> MizeResult<()> {
|
||||
parsers: Some(Vec::new()),
|
||||
mize: mize.clone(),
|
||||
};
|
||||
println!("hooooo");
|
||||
Ok(ItemData::from_native(state)?)
|
||||
}));
|
||||
|
||||
|
||||
method("set_command", |args| {
|
||||
println!("in set command");
|
||||
let mut state = get_config("self.state")?.native_mut::<CliPartState>()?;
|
||||
let cmd = args.arr_nth(0)?.native::<String>()?;
|
||||
let cmd = args.get_path("0")?.native::<String>()?;
|
||||
state.current_cmd_name = cmd.to_owned();
|
||||
if !state.cmds.contains_key(&*cmd) {
|
||||
state.cmds
|
||||
@@ -40,10 +37,9 @@ pub extern "C" fn part_cli() -> MizeResult<()> {
|
||||
});
|
||||
|
||||
method("subcommand", |args| {
|
||||
println!("in subcommand");
|
||||
let mut state = get_config("self.state")?.native_mut::<CliPartState>()?;
|
||||
let subcmd = args.arr_nth(0)?.native_take::<clap::Command>()?;
|
||||
let action = args.arr_nth(1)?.native_take::<Box<dyn Fn(ArgMatches) -> MizeResult<()> + Send + Sync>>()?;
|
||||
let subcmd = args.get_path("0")?.native_take::<clap::Command>()?;
|
||||
let action = args.get_path("1")?;
|
||||
let name = subcmd.get_name().to_string();
|
||||
let cur_cmd_name = state.current_cmd_name.clone();
|
||||
let cmd = state
|
||||
@@ -56,6 +52,23 @@ pub extern "C" fn part_cli() -> MizeResult<()> {
|
||||
Ok(ItemData::new())
|
||||
});
|
||||
|
||||
method("run", |args| {
|
||||
let cmdline = args.get_path("0")?.native_take::<Vec<String>>()?;
|
||||
let mut state = get_config("self.state")?.native_mut::<CliPartState>()?;
|
||||
let cmd_name = cmdline.iter().nth(0).ok_or(mize_err!("empty cmdline"))?;
|
||||
let cmd = state.cmds.remove(cmd_name).ok_or(mize_err!("cmd {} not found in CliPart", cmd_name))?;
|
||||
|
||||
let matches = cmd.get_matches_from(cmdline);
|
||||
let sub_name = matches.subcommand_name().ok_or(mize_err!("subcommand not found"))?;
|
||||
let sub_matches = matches.subcommand_matches(sub_name).ok_or(mize_err!("subcommand matches not found"))?;
|
||||
let action = state.actions.remove(sub_name).ok_or(mize_err!("action for subcommand not found"))?;
|
||||
let mut args = ItemData::new();
|
||||
args.set_path("0", ItemData::from_native(sub_matches.clone())?);
|
||||
action.call(args)?;
|
||||
|
||||
Ok(ItemData::new())
|
||||
});
|
||||
|
||||
// TODO in future....
|
||||
// Register methods from the impl block
|
||||
//CliPartState::methods_from_impl()?;
|
||||
@@ -67,7 +80,7 @@ pub struct CliPartState {
|
||||
cmds: HashMap<String, Command>,
|
||||
current_cmd_name: String,
|
||||
actions:
|
||||
HashMap<String, Box<dyn Fn(ArgMatches) -> MizeResult<()> + Send + Sync + 'static>>,
|
||||
HashMap<String, ItemData>,
|
||||
parsers: Option<Vec<Box<dyn Fn(Mize, Vec<String>) -> MizeResult<()> + Send + Sync + 'static>>>,
|
||||
mize: Mize,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user