recent mize changes
This commit is contained in:
8
apps/obsidian-plugin/Cargo.toml
Normal file
8
apps/obsidian-plugin/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mize-obsidian-plugin"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
mize = { path = "../.." }
|
||||
marts = { path = "../../marts" }
|
||||
3
apps/obsidian-plugin/src/main.rs
Normal file
3
apps/obsidian-plugin/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
8
apps/os/Cargo.toml
Normal file
8
apps/os/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mize-bin"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
mize = { path = "../../" }
|
||||
marts = { path = "../../marts" }
|
||||
167
apps/os/src/cli.rs
Normal file
167
apps/os/src/cli.rs
Normal file
@@ -0,0 +1,167 @@
|
||||
use clap::ArgMatches;
|
||||
use core::result::Result::Err;
|
||||
use core::unimplemented;
|
||||
use flume::bounded;
|
||||
use home::home_dir;
|
||||
use mize::mize_err;
|
||||
use std::ffi::OsString;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use tracing::debug;
|
||||
|
||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||
use mize::instance::subscription::Subscription;
|
||||
use mize::instance::subscription::Update;
|
||||
use mize::instance::Mize;
|
||||
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)?)?;
|
||||
|
||||
let id = sub_matches
|
||||
.get_one::<String>("id")
|
||||
.ok_or(MizeError::new().msg("No id Argument specified"))?;
|
||||
|
||||
let item = instance.get(id)?;
|
||||
|
||||
let recurse_count = sub_matches.get_count("recurse");
|
||||
|
||||
println!("{}", item.as_data_full()?);
|
||||
return Ok(());
|
||||
|
||||
if recurse_count > 0 {
|
||||
println!("{}", item.id());
|
||||
println!("{}", item.as_data_full()?);
|
||||
} else {
|
||||
println!("{}", item);
|
||||
};
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn call(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn create(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let mut instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
let item = instance.new_item()?;
|
||||
|
||||
println!("id: {}", item.id());
|
||||
println!("with namespace: {}", item.id().namespace().as_real_string());
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn is_running(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
println!("not implemented");
|
||||
Err(mize_err!("not implemented"))
|
||||
}
|
||||
|
||||
pub fn mount(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn daemon(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
instance.wait();
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn set(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
let id = sub_matches
|
||||
.get_one::<String>("id")
|
||||
.ok_or(MizeError::new().msg("No id Argument specified"))?;
|
||||
|
||||
let value = sub_matches
|
||||
.get_one::<String>("value")
|
||||
.ok_or(MizeError::new().msg("No value Argument specified"))?;
|
||||
|
||||
instance.set_blocking(id, value.into_item_data())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn show(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
let id = sub_matches
|
||||
.get_one::<String>("id")
|
||||
.ok_or(MizeError::new().msg("No id Argument specified"))?;
|
||||
|
||||
let item = instance.get(id)?;
|
||||
|
||||
let (tx, rx) = bounded::<Update>(4);
|
||||
let sub = Subscription::from_sender(tx);
|
||||
instance.sub(id, sub)?;
|
||||
|
||||
println!("item: {}", item.as_data_full()?);
|
||||
|
||||
for update in rx {
|
||||
println!("####### GOT UPDATE #######");
|
||||
println!("item: {}", update.new_item()?.as_data_full()?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn stop(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn gui(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let mut instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
instance.load_part("mme")?;
|
||||
|
||||
instance.wait();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn format_cbor(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let mut input: Vec<u8> = Vec::new();
|
||||
let stdin = std::io::stdin();
|
||||
let mut handle = stdin.lock();
|
||||
//handle.read_to_end(&mut input);
|
||||
|
||||
let cbor_data = ciborium::from_reader(handle)?;
|
||||
let item_data = ItemData::from_cbor(cbor_data);
|
||||
|
||||
println!("{}", item_data);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_from_module(cmd: &str, sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
let default = OsString::default();
|
||||
let mut sub_cmd_line: Vec<OsString> = sub_matches
|
||||
.get_many::<OsString>("")
|
||||
.unwrap()
|
||||
.map(|e| e.to_owned())
|
||||
.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)?;
|
||||
|
||||
println!("running cli from part not implemented");
|
||||
//instance
|
||||
//.get_part(cmd)?
|
||||
//.run_cli(&instance, sub_cmd_line)
|
||||
//.ok_or(mize_err!(
|
||||
//"The Part '{cmd}' does not implement the run_cli() functionality"
|
||||
//))??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
161
apps/os/src/main.rs
Normal file
161
apps/os/src/main.rs
Normal file
@@ -0,0 +1,161 @@
|
||||
#![allow(warnings)]
|
||||
|
||||
use clap::builder::OsStr;
|
||||
use clap::{crate_version, Arg, Command};
|
||||
use clap::{ArgAction, ArgMatches};
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
use colored::Colorize;
|
||||
use mize::error::{MizeError, MizeResult};
|
||||
use mize::item::ItemData;
|
||||
use mize::platform::os::logging::init_logger;
|
||||
use mize::{instance, Mize};
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{mpsc, Mutex};
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::filter::EnvFilter;
|
||||
use tracing_subscriber::fmt::Subscriber;
|
||||
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
mod cli;
|
||||
|
||||
static APPNAME: &str = "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
|
||||
|
||||
let cli_matches = cli_matches();
|
||||
|
||||
init_logger(&cli_matches);
|
||||
|
||||
// match command
|
||||
let result = match cli_matches.subcommand() {
|
||||
// mi daemon
|
||||
Some(("daemon", sub_matches)) => cli::daemon(sub_matches),
|
||||
|
||||
Some(("is-running", sub_matches)) => cli::is_running(sub_matches),
|
||||
|
||||
// mi serve
|
||||
Some(("serve", sub_matches)) => cli::stop(sub_matches),
|
||||
|
||||
// mi mount
|
||||
Some(("mount", sub_matches)) => cli::mount(sub_matches),
|
||||
|
||||
// mi get
|
||||
Some(("get", sub_matches)) => cli::get(sub_matches),
|
||||
|
||||
// mi set
|
||||
Some(("set", sub_matches)) => cli::set(sub_matches),
|
||||
|
||||
// mi show
|
||||
Some(("show", sub_matches)) => cli::show(sub_matches),
|
||||
|
||||
// mi call
|
||||
Some(("call", sub_matches)) => cli::call(sub_matches),
|
||||
|
||||
// mi create
|
||||
Some(("create", sub_matches)) => cli::create(sub_matches),
|
||||
|
||||
// mi gui
|
||||
Some(("gui", sub_matches)) => cli::gui(sub_matches),
|
||||
|
||||
// mi format-cbor
|
||||
Some(("format-cbor", sub_matches)) => cli::format_cbor(sub_matches),
|
||||
|
||||
// some unknown command passed
|
||||
Some((cmd, sub_matches)) => cli::run_from_module(cmd, sub_matches),
|
||||
|
||||
None => Err(MizeError::new()
|
||||
.msg("No subcommand was passed. use --help to list availavle comamnds.")),
|
||||
};
|
||||
|
||||
if let Err(err) = result {
|
||||
err.log();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn cli_matches() -> clap::ArgMatches {
|
||||
let main = Command::new(APPNAME)
|
||||
.version(crate_version!())
|
||||
.author("Sebastian Moser")
|
||||
.about("The MiZe Command line tool")
|
||||
.allow_external_subcommands(true)
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.long("verbose")
|
||||
.short('v')
|
||||
.action(ArgAction::Count)
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("log-level")
|
||||
.long("log-level")
|
||||
.value_name("LOGLEVEL")
|
||||
.help("set the log-level to one of OFF, ERROR, WARN, INFO, DEBUG, TRACE")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("silent")
|
||||
.long("silent")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("set the log-level to OFF")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("folder")
|
||||
.short('f')
|
||||
.long("folder")
|
||||
.help("The folder the Instance stores all it's data and the socket for connections")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("config")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.help("overwrite config options")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("config-file")
|
||||
.long("config-file")
|
||||
.help("specify a config file")
|
||||
.global(true),
|
||||
)
|
||||
.subcommand(Command::new("daemon").about("Run a MiZe Instance as a daemon"))
|
||||
.subcommand(Command::new("stop").about("Stop a MiZe Instance"))
|
||||
.subcommand(Command::new("mount").aliases(["m"]))
|
||||
.subcommand(
|
||||
Command::new("get")
|
||||
.aliases(["g"])
|
||||
.arg(Arg::new("id").help("The id or path to get"))
|
||||
.arg(Arg::new("recurse").short('r').action(ArgAction::Count)),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("set")
|
||||
.aliases(["s"])
|
||||
.arg(Arg::new("id").help("The id or path to set"))
|
||||
.arg(Arg::new("value").help("The value to set the path to")),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("show")
|
||||
.aliases(["so"])
|
||||
.arg(Arg::new("id").help("The id or path to sub to and show")),
|
||||
)
|
||||
.subcommand(Command::new("call").aliases(["c"]))
|
||||
.subcommand(Command::new("create").aliases(["cr"]))
|
||||
.subcommand(Command::new("is-running").aliases(["isr"]))
|
||||
.subcommand(Command::new("gui"))
|
||||
.subcommand(Command::new("format-cbor"))
|
||||
.arg_required_else_help(true);
|
||||
|
||||
return main.get_matches();
|
||||
}
|
||||
Reference in New Issue
Block a user