basically fully restored
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use clap::ArgMatches;
|
||||
use marts::CliPart;
|
||||
use core::result::Result::Err;
|
||||
use core::unimplemented;
|
||||
use mize::flume::bounded;
|
||||
@@ -19,6 +18,8 @@ use mize::item::{IntoItemData, ItemData};
|
||||
use mize::platform::os::config_from_cli_args;
|
||||
use mize::platform::os::fsstore::FileStore;
|
||||
|
||||
use crate::generated;
|
||||
|
||||
pub fn get(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
|
||||
let id = sub_matches
|
||||
@@ -81,7 +82,7 @@ pub fn run(sub_matches: &ArgMatches, mize: &mut Mize) -> MizeResult<()> {
|
||||
let mut ext_cmdline = vec![runnable.to_owned()];
|
||||
ext_cmdline.append(&mut ext_args);
|
||||
|
||||
let mut cli = mize.get_part_native::<CliPart>("cli")?;
|
||||
let mut cli = generated::CliPart::get("cli")?;
|
||||
cli.run(ext_cmdline)?;
|
||||
}
|
||||
}
|
||||
|
||||
70
apps/os/src/generated.rs
Normal file
70
apps/os/src/generated.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
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<CliPart> {
|
||||
let mut mize = get_global_mize()?;
|
||||
let part = mize.get_part(name)?;
|
||||
Ok(CliPart { id: part.id() })
|
||||
}
|
||||
pub fn run(&self, cmdline: Vec<String>) -> 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<T: Fn(ArgMatches) -> 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<Command> {
|
||||
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 })
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ use std::sync::Arc;
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
mod cli;
|
||||
// the generated module by hand. as we need the mize-bin to run generate
|
||||
mod generated;
|
||||
|
||||
static APPNAME: &str = "mize";
|
||||
|
||||
@@ -61,6 +63,7 @@ fn tried_main() -> MizeResult<()> {
|
||||
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,
|
||||
@@ -70,7 +73,8 @@ fn tried_main() -> MizeResult<()> {
|
||||
"ppc.server": marts::ppc::server::part_ppc_server,
|
||||
"c2vi": marts::part_c2vi,
|
||||
"sci.timetrack": marts::sci::timetrack::part_timetrack,
|
||||
};
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
// match subcommand
|
||||
|
||||
Reference in New Issue
Block a user