the mize bin works
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -5047,8 +5047,10 @@ dependencies = [
|
|||||||
name = "mize-bin"
|
name = "mize-bin"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"clap",
|
||||||
"marts",
|
"marts",
|
||||||
"mize",
|
"mize",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ members = [
|
|||||||
]
|
]
|
||||||
default-members = [
|
default-members = [
|
||||||
"apps/obsidian-plugin",
|
"apps/obsidian-plugin",
|
||||||
|
"apps/os",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,9 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
mize = { path = "../../" }
|
mize = { path = "../../" }
|
||||||
marts = { path = "../../marts" }
|
marts = { path = "../../marts" }
|
||||||
|
clap = { version = "4.5.59", features = ["string"] }
|
||||||
|
tracing = "0.1.44"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mize"
|
||||||
|
path = "./src/main.rs"
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use core::result::Result::Err;
|
use core::result::Result::Err;
|
||||||
use core::unimplemented;
|
use core::unimplemented;
|
||||||
use flume::bounded;
|
use mize::flume::bounded;
|
||||||
use home::home_dir;
|
|
||||||
use mize::mize_err;
|
use mize::mize_err;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
use mize::ciborium;
|
||||||
|
|
||||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||||
use mize::instance::subscription::Subscription;
|
use mize::instance::subscription::Subscription;
|
||||||
@@ -43,6 +43,7 @@ pub fn get(sub_matches: &ArgMatches) -> MizeResult<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn call(sub_matches: &ArgMatches) -> MizeResult<()> {
|
pub fn call(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||||
|
println!("call cmd not implemented");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,16 +58,17 @@ pub fn create(sub_matches: &ArgMatches) -> MizeResult<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_running(sub_matches: &ArgMatches) -> MizeResult<()> {
|
pub fn status(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||||
println!("not implemented");
|
println!("not implemented");
|
||||||
Err(mize_err!("not implemented"))
|
Err(mize_err!("not implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mount(sub_matches: &ArgMatches) -> MizeResult<()> {
|
pub fn info(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||||
Ok(())
|
println!("not implemented");
|
||||||
|
Err(mize_err!("not implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn daemon(sub_matches: &ArgMatches) -> MizeResult<()> {
|
pub fn run(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||||
|
|
||||||
instance.wait();
|
instance.wait();
|
||||||
@@ -91,38 +93,25 @@ pub fn set(sub_matches: &ArgMatches) -> MizeResult<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(sub_matches: &ArgMatches) -> MizeResult<()> {
|
pub fn show(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||||
let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
println!("not implemented");
|
||||||
|
// let instance = Mize::with_config(config_from_cli_args(sub_matches)?)?;
|
||||||
|
|
||||||
let id = sub_matches
|
// let id = sub_matches
|
||||||
.get_one::<String>("id")
|
// .get_one::<String>("id")
|
||||||
.ok_or(MizeError::new().msg("No id Argument specified"))?;
|
// .ok_or(MizeError::new().msg("No id Argument specified"))?;
|
||||||
|
|
||||||
let item = instance.get(id)?;
|
// let item = instance.get(id)?;
|
||||||
|
|
||||||
let (tx, rx) = bounded::<Update>(4);
|
// let (tx, rx) = bounded::<Update>(4);
|
||||||
let sub = Subscription::from_sender(tx);
|
// let sub = Subscription::from_sender(tx);
|
||||||
instance.sub(id, sub)?;
|
// instance.sub(id, sub)?;
|
||||||
|
|
||||||
println!("item: {}", item.as_data_full()?);
|
// println!("item: {}", item.as_data_full()?);
|
||||||
|
|
||||||
for update in rx {
|
// for update in rx {
|
||||||
println!("####### GOT UPDATE #######");
|
// println!("####### GOT UPDATE #######");
|
||||||
println!("item: {}", update.new_item()?.as_data_full()?);
|
// 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -141,7 +130,7 @@ pub fn format_cbor(sub_matches: &ArgMatches) -> MizeResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_from_module(cmd: &str, sub_matches: &ArgMatches) -> MizeResult<()> {
|
pub fn run_from_part(cmd: &str, sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||||
let default = OsString::default();
|
let default = OsString::default();
|
||||||
let mut sub_cmd_line: Vec<OsString> = sub_matches
|
let mut sub_cmd_line: Vec<OsString> = sub_matches
|
||||||
.get_many::<OsString>("")
|
.get_many::<OsString>("")
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use std::ffi::OsString;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use colored::Colorize;
|
|
||||||
use mize::error::{MizeError, MizeResult};
|
use mize::error::{MizeError, MizeResult};
|
||||||
use mize::item::ItemData;
|
use mize::item::ItemData;
|
||||||
use mize::platform::os::logging::init_logger;
|
use mize::platform::os::logging::init_logger;
|
||||||
@@ -15,11 +14,6 @@ use mize::{instance, Mize};
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::sync::Arc;
|
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};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
@@ -38,41 +32,18 @@ fn main() {
|
|||||||
|
|
||||||
// match command
|
// match command
|
||||||
let result = match cli_matches.subcommand() {
|
let result = match cli_matches.subcommand() {
|
||||||
// mi daemon
|
Some(("run", sub_matches)) => cli::run(sub_matches),
|
||||||
Some(("daemon", sub_matches)) => cli::daemon(sub_matches),
|
Some(("status", sub_matches)) => cli::status(sub_matches),
|
||||||
|
Some(("info", sub_matches)) => cli::info(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),
|
Some(("get", sub_matches)) => cli::get(sub_matches),
|
||||||
|
|
||||||
// mi set
|
|
||||||
Some(("set", sub_matches)) => cli::set(sub_matches),
|
Some(("set", sub_matches)) => cli::set(sub_matches),
|
||||||
|
|
||||||
// mi show
|
|
||||||
Some(("show", sub_matches)) => cli::show(sub_matches),
|
Some(("show", sub_matches)) => cli::show(sub_matches),
|
||||||
|
|
||||||
// mi call
|
|
||||||
Some(("call", sub_matches)) => cli::call(sub_matches),
|
Some(("call", sub_matches)) => cli::call(sub_matches),
|
||||||
|
|
||||||
// mi create
|
|
||||||
Some(("create", sub_matches)) => cli::create(sub_matches),
|
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(("format-cbor", sub_matches)) => cli::format_cbor(sub_matches),
|
||||||
|
|
||||||
// some unknown command passed
|
Some((cmd, sub_matches)) => cli::run_from_part(cmd, sub_matches),
|
||||||
Some((cmd, sub_matches)) => cli::run_from_module(cmd, sub_matches),
|
|
||||||
|
|
||||||
None => Err(MizeError::new()
|
None => Err(MizeError::new()
|
||||||
.msg("No subcommand was passed. use --help to list availavle comamnds.")),
|
.msg("No subcommand was passed. use --help to list availavle comamnds.")),
|
||||||
};
|
};
|
||||||
@@ -87,7 +58,7 @@ fn cli_matches() -> clap::ArgMatches {
|
|||||||
let main = Command::new(APPNAME)
|
let main = Command::new(APPNAME)
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.author("Sebastian Moser")
|
.author("Sebastian Moser")
|
||||||
.about("The MiZe Command line tool")
|
.about("MiZe")
|
||||||
.allow_external_subcommands(true)
|
.allow_external_subcommands(true)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("verbose")
|
Arg::new("verbose")
|
||||||
@@ -104,35 +75,30 @@ fn cli_matches() -> clap::ArgMatches {
|
|||||||
.global(true),
|
.global(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("silent")
|
Arg::new("log")
|
||||||
.long("silent")
|
.long("log")
|
||||||
.action(ArgAction::SetTrue)
|
.help("log file to use")
|
||||||
.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),
|
.global(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("config")
|
Arg::new("config")
|
||||||
.short('c')
|
|
||||||
.long("config")
|
.long("config")
|
||||||
.help("overwrite config options")
|
.help("config file path")
|
||||||
.global(true),
|
.global(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("config-file")
|
Arg::new("secrets")
|
||||||
.long("config-file")
|
.long("secrets")
|
||||||
.help("specify a config file")
|
.help("file path to store secrets at")
|
||||||
|
.global(true),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("opt")
|
||||||
|
.short('o')
|
||||||
|
.long("opt")
|
||||||
|
.help("overwrite a config option")
|
||||||
.global(true),
|
.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(
|
.subcommand(
|
||||||
Command::new("get")
|
Command::new("get")
|
||||||
.aliases(["g"])
|
.aliases(["g"])
|
||||||
@@ -152,9 +118,9 @@ fn cli_matches() -> clap::ArgMatches {
|
|||||||
)
|
)
|
||||||
.subcommand(Command::new("call").aliases(["c"]))
|
.subcommand(Command::new("call").aliases(["c"]))
|
||||||
.subcommand(Command::new("create").aliases(["cr"]))
|
.subcommand(Command::new("create").aliases(["cr"]))
|
||||||
.subcommand(Command::new("is-running").aliases(["isr"]))
|
.subcommand(Command::new("status").aliases(["st"]))
|
||||||
.subcommand(Command::new("gui"))
|
.subcommand(Command::new("run"))
|
||||||
.subcommand(Command::new("format-cbor"))
|
.subcommand(Command::new("format-cbor").aliases(["fc"]))
|
||||||
.arg_required_else_help(true);
|
.arg_required_else_help(true);
|
||||||
|
|
||||||
return main.get_matches();
|
return main.get_matches();
|
||||||
|
|||||||
@@ -257,7 +257,6 @@ in {
|
|||||||
pkgs.systemd
|
pkgs.systemd
|
||||||
pkgs.rsync
|
pkgs.rsync
|
||||||
pkgs.openssh
|
pkgs.openssh
|
||||||
pkgs.git
|
|
||||||
pkgs.cmake
|
pkgs.cmake
|
||||||
|
|
||||||
# to build ../grid
|
# to build ../grid
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
static PROTO_VERSION: u8 = 1;
|
static PROTO_VERSION: u8 = 1;
|
||||||
|
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::format;
|
use std::fmt::format;
|
||||||
|
|
||||||
|
|||||||
@@ -159,16 +159,6 @@ pub fn init_logger(cli_matches: &ArgMatches) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check --silent flag
|
|
||||||
if cli_matches.get_flag("silent") {
|
|
||||||
if log_level != DEFAULT_LOG_LEVEL {
|
|
||||||
log_messages.push((Level::WARN, format!(
|
|
||||||
"The loglevel was set by some method (it's not the DEFAULT_LOG_LEVEL) and is now overwritten by the --siltne to be OFF"
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
log_level = LevelFilter::OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
// actually set the log_level on the builder
|
// actually set the log_level on the builder
|
||||||
log_messages.push((Level::INFO, format!("loglevel is now {}", log_level)));
|
log_messages.push((Level::INFO, format!("loglevel is now {}", log_level)));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user