set msg
This commit is contained in:
22
src/platform/os/cli/create.rs
Normal file
22
src/platform/os/cli/create.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use home::home_dir;
|
||||
|
||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||
use mize::instance::Instance;
|
||||
use mize::platform::os::config_from_cli_args;
|
||||
|
||||
|
||||
|
||||
pub fn create(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
let mut instance = Instance::with_config(config_from_cli_args(sub_matches)?)?;
|
||||
|
||||
let item = instance.new_item()?;
|
||||
|
||||
println!("id: {}", item.id());
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
27
src/platform/os/cli/is_running.rs
Normal file
27
src/platform/os/cli/is_running.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use home::home_dir;
|
||||
|
||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||
use mize::instance::Instance;
|
||||
use mize::platform::os::config_from_cli_args;
|
||||
|
||||
use mize::platform::os::fsstore::FileStore;
|
||||
//use self::FileStore;
|
||||
|
||||
|
||||
pub fn is_running(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
let home_dir = env!("HOME");
|
||||
|
||||
if FileStore::store_is_opened(home_dir.to_owned() + "/.mize")? {
|
||||
println!("true");
|
||||
} else {
|
||||
println!("false");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,34 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use mize::error::MizeResult;
|
||||
use home::home_dir;
|
||||
|
||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||
use mize::instance::Instance;
|
||||
use mize::platform::os::config_from_cli_args;
|
||||
|
||||
|
||||
|
||||
pub fn set(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
|
||||
let instance = Instance::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(());
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ impl FileStore {
|
||||
|
||||
} else {
|
||||
// write our own pid file
|
||||
fs::remove_file(path.join("pid"));
|
||||
let pid = std::process::id();
|
||||
let mut file = OpenOptions::new().write(true).create(true).open(path.join("pid"))?;
|
||||
write!(file, "{}", pid)?;
|
||||
|
||||
@@ -28,14 +28,19 @@ mod cli {
|
||||
pub mod show;
|
||||
pub mod mount;
|
||||
pub mod call;
|
||||
pub mod create;
|
||||
pub mod is_running;
|
||||
|
||||
|
||||
pub use run::run;
|
||||
pub use stop::stop;
|
||||
pub use get::get;
|
||||
pub use set::set;
|
||||
pub use show::show;
|
||||
pub use create::create;
|
||||
pub use mount::mount;
|
||||
pub use call::call;
|
||||
pub use is_running::is_running;
|
||||
}
|
||||
|
||||
mod logging;
|
||||
@@ -57,6 +62,8 @@ fn main() {
|
||||
// mi daemon
|
||||
Some(("run", sub_matches)) => cli::run(sub_matches),
|
||||
|
||||
Some(("is-running", sub_matches)) => cli::is_running(sub_matches),
|
||||
|
||||
// mi serve
|
||||
Some(("serve", sub_matches)) => cli::stop(sub_matches),
|
||||
|
||||
@@ -75,6 +82,9 @@ fn main() {
|
||||
// mi call
|
||||
Some(("call", sub_matches)) => cli::call(sub_matches),
|
||||
|
||||
// mi create
|
||||
Some(("create", sub_matches)) => cli::create(sub_matches),
|
||||
|
||||
// some unknown command passed
|
||||
Some((cmd, sub_matches)) => Err(MizeError::new().msg(format!("The subcommand: {} is not known. use --help to list availavle commands", cmd))),
|
||||
|
||||
@@ -164,6 +174,14 @@ fn cli_matches() -> clap::ArgMatches {
|
||||
Command::new("call")
|
||||
.aliases(["c"])
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("create")
|
||||
.aliases(["cr"])
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("is-running")
|
||||
.aliases(["isr"])
|
||||
)
|
||||
.arg_required_else_help(true);
|
||||
|
||||
return main.get_matches();
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::platform::os::unix_socket::UnixListener;
|
||||
|
||||
use self::fsstore::FileStore;
|
||||
|
||||
mod fsstore;
|
||||
pub mod fsstore;
|
||||
mod unix_socket;
|
||||
//mod web;
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ async fn unix_listen(listener: UnixListener, mut instance: Instance) -> MizeResu
|
||||
|
||||
fn unix_outgoing(mut unix_write: OwnedWriteHalf, send_rx: Receiver<MizeMessage>, mut instance: Instance, conn_id: u64) -> MizeResult<()> {
|
||||
for msg in send_rx {
|
||||
println!("unix outgoing got msg: {:?}", msg);
|
||||
println!("unix outgoing got msg: {}", msg);
|
||||
let adapter = MyCiboriumWriter { inner: &mut unix_write, instance: &mut instance };
|
||||
let value = msg.value();
|
||||
ciborium::into_writer(&value, adapter)?
|
||||
@@ -139,7 +139,7 @@ fn unix_incomming(mut unix_read: OwnedReadHalf, mut instance: Instance, conn_id:
|
||||
break;
|
||||
}
|
||||
let msg = MizeMessage::new(value, conn_id);
|
||||
println!("unix incoming got msg: {:?}", msg);
|
||||
println!("unix incoming got msg: {}", msg);
|
||||
instance.got_msg(msg);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user