added ppc server and mize run external subcommands
This commit is contained in:
@@ -2,7 +2,7 @@ use clap::ArgMatches;
|
||||
use core::result::Result::Err;
|
||||
use core::unimplemented;
|
||||
use mize::flume::bounded;
|
||||
use mize::mize_err;
|
||||
use mize::{instance, mize_err};
|
||||
use std::ffi::OsString;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
@@ -18,8 +18,7 @@ use mize::item::{IntoItemData, ItemData};
|
||||
use mize::platform::os::config_from_cli_args;
|
||||
use mize::platform::os::fsstore::FileStore;
|
||||
|
||||
pub fn get(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
pub fn get(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
|
||||
let id = sub_matches
|
||||
.get_one::<String>("id")
|
||||
@@ -42,13 +41,12 @@ pub fn get(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn call(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
pub fn call(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
println!("call cmd not implemented");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn create(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let mut instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
pub fn create(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
|
||||
let item = instance.new_item()?;
|
||||
|
||||
@@ -58,27 +56,37 @@ pub fn create(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn status(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
pub fn status(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
println!("not implemented");
|
||||
Err(mize_err!("not implemented"))
|
||||
}
|
||||
|
||||
pub fn info(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
pub fn info(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
println!("not implemented");
|
||||
Err(mize_err!("not implemented"))
|
||||
}
|
||||
|
||||
pub fn run(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
pub fn run(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
match sub_matches.subcommand() {
|
||||
None => {
|
||||
instance.wait();
|
||||
}
|
||||
Some((runnable, sub_matches)) => {
|
||||
let ext_args: Vec<String> = sub_matches
|
||||
.get_many::<OsString>("")
|
||||
.unwrap_or_default()
|
||||
.map(|v| v.to_string_lossy().to_string())
|
||||
.collect();
|
||||
|
||||
println!("runnable: {}", runnable);
|
||||
println!("args: {:?}", ext_args);
|
||||
}
|
||||
}
|
||||
|
||||
instance.wait();
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
pub fn set(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
let id = sub_matches
|
||||
.get_one::<String>("id")
|
||||
.ok_or(MizeError::new().msg("No id Argument specified"))?;
|
||||
@@ -92,7 +100,7 @@ pub fn set(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn show(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
pub fn show(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
println!("not implemented");
|
||||
// let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
@@ -116,7 +124,7 @@ pub fn show(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn format_cbor(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
pub fn format_cbor(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
let mut input: Vec<u8> = Vec::new();
|
||||
let stdin = std::io::stdin();
|
||||
let mut handle = stdin.lock();
|
||||
@@ -130,7 +138,7 @@ pub fn format_cbor(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_from_part(cmd: &str, sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
pub fn run_from_part(cmd: &str, sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
||||
let default = OsString::default();
|
||||
let mut sub_cmd_line: Vec<OsString> = sub_matches
|
||||
.get_many::<OsString>("")
|
||||
@@ -139,8 +147,6 @@ pub fn run_from_part(cmd: &str, sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
.collect();
|
||||
sub_cmd_line.insert(0, OsString::from_str(cmd)?);
|
||||
|
||||
let mut instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
debug!("loading module '{}'", cmd);
|
||||
instance.load_part(cmd)?;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user