restorations from agent session
This commit is contained in:
58
core/Cargo.toml
Normal file
58
core/Cargo.toml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
[package]
|
||||||
|
name = "mize"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2024"
|
||||||
|
license = "GPL-3.0"
|
||||||
|
description = 'A strongly typed "filesystem" for the age of connectivity.'
|
||||||
|
repository = "https://git.ppc.social/ppc/mize"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "mize"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
crate-type = [ "cdylib", "rlib" ]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = [ "target-os" ]
|
||||||
|
target-os = [ "clap", "home", "nix", "sysinfo", "ciborium/default", "tracing-subscriber", "async", "tracing-subscriber/env-filter", "libloading", "ciborium-io", "tracing-core", "tar", "flate2", "http_req", "tokio/net", "tokio", "tokio/rt-multi-thread", "tokio/io-util", "cmd_lib" ]
|
||||||
|
target-js = [ "wasm-bindgen", "console_error_panic_hook", "web-sys", "web-sys/Worker", "web-sys/Window", "web-sys/Request", "web-sys/RequestInit", "web-sys/RequestMode", "web-sys/Response", "web-sys/WorkerOptions", "web-sys/WorkerType", "serde-wasm-bindgen", "wasm-bindgen-futures", "wee_alloc", "ciborium/default" ]
|
||||||
|
async = [ "tokio", ]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# core dependencies
|
||||||
|
colored = "2.0.0"
|
||||||
|
uuid = "1.3.0"
|
||||||
|
ciborium = { version = "0.2.2", default-features = false }
|
||||||
|
serde = "1.0.203"
|
||||||
|
interner = { git = "https://github.com/c2vi/interner" }
|
||||||
|
tracing = "0.1.40"
|
||||||
|
serde_json = { version = "1.0.117", optional = false }
|
||||||
|
toml = { version = "0.8.13", features = ["parse"], optional = false }
|
||||||
|
dyn-clone = "1.0.17"
|
||||||
|
sha2 = "0.10.8"
|
||||||
|
flume = { version = "0.11.1", default-features = false, features = [ "async" ] }
|
||||||
|
mize_macros = { path = "../macros" }
|
||||||
|
async-trait = "0.1.89"
|
||||||
|
|
||||||
|
# wasm dependencies
|
||||||
|
wasm-bindgen = { version = "0.2.84", optional = true }
|
||||||
|
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||||
|
web-sys = { version = "0.3.70", optional = true }
|
||||||
|
serde-wasm-bindgen = { version = "0.6.5", optional = true }
|
||||||
|
wasm-bindgen-futures = { version = "0.4.49", optional = true }
|
||||||
|
wee_alloc = { version = "0.4.5", optional = true }
|
||||||
|
|
||||||
|
# os dependencies
|
||||||
|
clap = { version = "4.4.11", features = ["cargo"], optional = true }
|
||||||
|
home = { version = "0.5.9", optional = true }
|
||||||
|
daemonize = { version = "0.5.0", optional = true }
|
||||||
|
nix = { version = "0.27.1", features = ["signal"], optional = true }
|
||||||
|
sysinfo = { version = "0.30.12", optional = true }
|
||||||
|
tracing-subscriber = { version = "0.3.18", optional = true }
|
||||||
|
tokio = { version = "1.46.1", features = ["sync", "rt" ], optional = true, default-features = false }
|
||||||
|
libloading = { version = "0.8.5", optional = true }
|
||||||
|
ciborium-io = { version = "0.2.2", optional = true }
|
||||||
|
tracing-core = { version = "0.1.32", optional = true }
|
||||||
|
tar = { version = "0.4.42", optional = true }
|
||||||
|
flate2 = { version = "1.0.33", optional = true }
|
||||||
|
http_req = { version = "0.12.0", default-features = false, features = [ "rust-tls" ], optional = true }
|
||||||
22
parts/cli/Cargo.toml
Normal file
22
parts/cli/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
cargo-features = ["profile-rustflags"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "mize-part-cli"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "mize_part_cli"
|
||||||
|
crate-type = [ "dylib", "rlib" ]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.6.7", features = [ "string" ] }
|
||||||
|
log = "0.4.34"
|
||||||
|
mize = { workspace = true }
|
||||||
|
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
rustflags = ["-C", "prefer-dynamic", "-C", "link-args=-Wl,--export-dynamic"]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
rustflags = ["-C", "prefer-dynamic"]
|
||||||
@@ -1,10 +1,135 @@
|
|||||||
use mize_macros::{include_native_simple, part_impl};
|
use clap::{ArgMatches, Command};
|
||||||
use clap::Command;
|
use mize::item::ItemData;
|
||||||
|
use mize_macros::{include_native, part_impl};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use mize::prelude::*;
|
||||||
|
|
||||||
#[part_impl]
|
#[unsafe(no_mangle)]
|
||||||
pub fn part() -> mize::Instance {
|
pub extern "C" fn part_cli() -> MizeResult<()> {
|
||||||
// Register the command with the new macro syntax
|
|
||||||
include_native_simple!("Command", clap::Command, [new]);
|
include_native!("Command", clap::Command, [new]);
|
||||||
|
|
||||||
mize::Instance::new()
|
opt("state")
|
||||||
|
.fun(Box::new(|| {
|
||||||
|
println!("hiiiiii");
|
||||||
|
let mize = get_global_mize().unwrap();
|
||||||
|
let state = CliPartState {
|
||||||
|
cmds: HashMap::new(),
|
||||||
|
current_cmd_name: "marts-cli".to_string(),
|
||||||
|
actions: HashMap::new(),
|
||||||
|
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>()?;
|
||||||
|
state.current_cmd_name = cmd.to_owned();
|
||||||
|
if !state.cmds.contains_key(&*cmd) {
|
||||||
|
state.cmds
|
||||||
|
.insert((*cmd).to_owned(), Command::new((*cmd).to_owned()));
|
||||||
|
}
|
||||||
|
Ok(ItemData::new())
|
||||||
|
});
|
||||||
|
|
||||||
|
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 name = subcmd.get_name().to_string();
|
||||||
|
let cur_cmd_name = state.current_cmd_name.clone();
|
||||||
|
let cmd = state
|
||||||
|
.cmds
|
||||||
|
.remove(&cur_cmd_name)
|
||||||
|
.unwrap()
|
||||||
|
.subcommand(subcmd);
|
||||||
|
state.cmds.insert(cur_cmd_name.clone(), cmd);
|
||||||
|
state.actions.insert(name, action);
|
||||||
|
Ok(ItemData::new())
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO in future....
|
||||||
|
// Register methods from the impl block
|
||||||
|
//CliPartState::methods_from_impl()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CliPartState {
|
||||||
|
cmds: HashMap<String, Command>,
|
||||||
|
current_cmd_name: String,
|
||||||
|
actions:
|
||||||
|
HashMap<String, Box<dyn Fn(ArgMatches) -> MizeResult<()> + Send + Sync + 'static>>,
|
||||||
|
parsers: Option<Vec<Box<dyn Fn(Mize, Vec<String>) -> MizeResult<()> + Send + Sync + 'static>>>,
|
||||||
|
mize: Mize,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
#[part_impl]
|
||||||
|
impl CliPartState {
|
||||||
|
pub fn set_command(&mut self, cmd: &str) {
|
||||||
|
self.current_cmd_name = cmd.to_owned();
|
||||||
|
if !self.cmds.contains_key(cmd) {
|
||||||
|
self.cmds
|
||||||
|
.insert(cmd.to_owned(), Command::new(cmd.to_owned()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn subcommand(
|
||||||
|
&mut self,
|
||||||
|
subcmd: Command,
|
||||||
|
action: Box<dyn Fn(&ArgMatches, Mize) -> MizeResult<()> + Send + Sync + 'static>,
|
||||||
|
) -> MizeResult<()> {
|
||||||
|
let name = subcmd.get_name().to_string();
|
||||||
|
let cmd = self
|
||||||
|
.cmds
|
||||||
|
.remove(&self.current_cmd_name)
|
||||||
|
.unwrap()
|
||||||
|
.subcommand(subcmd);
|
||||||
|
self.cmds.insert(self.current_cmd_name.clone(), cmd);
|
||||||
|
self.actions.insert(name, action);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn add_sub_parser<T: Fn(Mize, Vec<String>) -> MizeResult<()> + Send + Sync + 'static>(
|
||||||
|
&mut self,
|
||||||
|
parser: T,
|
||||||
|
) -> MizeResult<()> {
|
||||||
|
self.parsers.as_mut().unwrap().push(Box::new(parser));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub fn with_cmd(
|
||||||
|
&mut self,
|
||||||
|
func: fn(cmd: Command) -> MizeResult<Command>,
|
||||||
|
) -> MizeResult<()> {
|
||||||
|
let cmd = self.cmds.remove(&self.current_cmd_name).ok_or(mize_err!(
|
||||||
|
"current command {} not found",
|
||||||
|
self.current_cmd_name
|
||||||
|
))?;
|
||||||
|
let cmd = func(cmd)?;
|
||||||
|
self.cmds.insert(self.current_cmd_name.clone(), cmd);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
pub fn run(&mut self, cmdline: Vec<String>) -> MizeResult<()> {
|
||||||
|
let cmd_name = cmdline.iter().nth(0).ok_or(mize_err!("empty cmdline"))?;
|
||||||
|
let cmd = self.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 = self.actions.remove(sub_name).ok_or(mize_err!("action for subcommand not found"))?;
|
||||||
|
action(sub_matches, self.mize.clone())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user