timetrack works locally
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
use marts::CliPart;
|
||||||
use core::result::Result::Err;
|
use core::result::Result::Err;
|
||||||
use core::unimplemented;
|
use core::unimplemented;
|
||||||
use mize::flume::bounded;
|
use mize::flume::bounded;
|
||||||
@@ -66,20 +67,22 @@ pub fn info(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
|||||||
Err(mize_err!("not implemented"))
|
Err(mize_err!("not implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(sub_matches: &ArgMatches, instance: &mut Mize) -> MizeResult<()> {
|
pub fn run(sub_matches: &ArgMatches, mize: &mut Mize) -> MizeResult<()> {
|
||||||
match sub_matches.subcommand() {
|
match sub_matches.subcommand() {
|
||||||
None => {
|
None => { // run a mize instance (does whatever it's config will say)
|
||||||
instance.wait();
|
mize.wait();
|
||||||
}
|
}
|
||||||
Some((runnable, sub_matches)) => {
|
Some((runnable, sub_matches)) => { // run smth from a part. for now registered cli commands
|
||||||
let ext_args: Vec<String> = sub_matches
|
let mut ext_args: Vec<String> = sub_matches
|
||||||
.get_many::<OsString>("")
|
.get_many::<OsString>("")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.map(|v| v.to_string_lossy().to_string())
|
.map(|v| v.to_string_lossy().to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
let mut ext_cmdline = vec![runnable.to_owned()];
|
||||||
|
ext_cmdline.append(&mut ext_args);
|
||||||
|
|
||||||
println!("runnable: {}", runnable);
|
let mut cli = mize.get_part_native::<CliPart>("cli")?;
|
||||||
println!("args: {:?}", ext_args);
|
cli.run(ext_cmdline)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ macro_rules! compile_in_parts {
|
|||||||
$(
|
$(
|
||||||
if enable_str.contains(&$name) {
|
if enable_str.contains(&$name) {
|
||||||
tracing::info!("enabling compiled_in_part: {}", $name);
|
tracing::info!("enabling compiled_in_part: {}", $name);
|
||||||
$part(&mut $mize);
|
if let Err(e) = $part(&mut $mize) {
|
||||||
|
print!("part '{}' failed with: ", $name);
|
||||||
|
e.log();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)+
|
)+
|
||||||
};
|
};
|
||||||
@@ -66,6 +69,7 @@ fn tried_main() -> MizeResult<()> {
|
|||||||
//"matrix": marts::part_matrix,
|
//"matrix": marts::part_matrix,
|
||||||
"ppc.server": marts::ppc::server::part_ppc_server,
|
"ppc.server": marts::ppc::server::part_ppc_server,
|
||||||
"c2vi": marts::part_c2vi,
|
"c2vi": marts::part_c2vi,
|
||||||
|
"sci.timetrack": marts::timetrack::part_timetrack,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::{path::PathBuf, thread};
|
use std::{path::PathBuf, thread};
|
||||||
use tracing::info;
|
use tracing::{info, warn};
|
||||||
|
|
||||||
// console_log macro
|
// console_log macro
|
||||||
// that can be copied into other files for debugging purposes
|
// that can be copied into other files for debugging purposes
|
||||||
@@ -658,6 +658,11 @@ fn update_spacetimedb_token(new_token: &str) -> MizeResult<()> {
|
|||||||
|
|
||||||
let file_path = config_dir.join("spacetime").join("cli.toml");
|
let file_path = config_dir.join("spacetime").join("cli.toml");
|
||||||
|
|
||||||
|
if !file_path.exists() {
|
||||||
|
warn!("spacetime config file does not exist, not updating token there");
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
// Read existing file (or create empty document if it doesn't exist)
|
// Read existing file (or create empty document if it doesn't exist)
|
||||||
let content = std::fs::read_to_string(&file_path).unwrap_or_default();
|
let content = std::fs::read_to_string(&file_path).unwrap_or_default();
|
||||||
let mut data = ItemData::from_toml(content.as_str())?;
|
let mut data = ItemData::from_toml(content.as_str())?;
|
||||||
|
|||||||
@@ -28,7 +28,17 @@ pub fn cli_spawn_setup(mize: Mize, conn_id: u64, wait_rx: flume::Receiver<()>) -
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cli_spawn(cmd: String) -> MizeResult<()> {
|
pub fn cli_spawn(mize: &mut Mize, cmd: String) -> MizeResult<()> {
|
||||||
|
// spawn locally
|
||||||
|
if !mize.get_config("cli.daemonMode").unwrap_or(ItemData::new()).as_bool().unwrap_or(false) {
|
||||||
|
std::process::Command::new("/bin/sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(&cmd)
|
||||||
|
.status()?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// for spawning in the client if we are running in the daemon (which is eg attached to the users tty)
|
||||||
MIZE_CLI_SPAWN.with(|cell| {
|
MIZE_CLI_SPAWN.with(|cell| {
|
||||||
if let Some(spawn) = cell.borrow().as_ref() {
|
if let Some(spawn) = cell.borrow().as_ref() {
|
||||||
let conn_id = spawn.conn_id.ok_or(mize_err!("no conn_id set"))?;
|
let conn_id = spawn.conn_id.ok_or(mize_err!("no conn_id set"))?;
|
||||||
@@ -143,8 +153,8 @@ fn cli_msg_handler(
|
|||||||
mize: &mut Mize,
|
mize: &mut Mize,
|
||||||
spawn_wait_rx: flume::Receiver<()>,
|
spawn_wait_rx: flume::Receiver<()>,
|
||||||
) -> MizeResult<()> {
|
) -> MizeResult<()> {
|
||||||
let binding = msg.data()?;
|
let tmp = msg.data()?;
|
||||||
let data = binding
|
let data = tmp
|
||||||
.cbor()
|
.cbor()
|
||||||
.as_array()
|
.as_array()
|
||||||
.ok_or(mize_err!("cli message data was not an array"))?;
|
.ok_or(mize_err!("cli message data was not an array"))?;
|
||||||
@@ -274,4 +284,16 @@ impl CliPart {
|
|||||||
self.cmds.insert(self.current_cmd_name.clone(), cmd);
|
self.cmds.insert(self.current_cmd_name.clone(), cmd);
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ pub struct TimeTrack {
|
|||||||
mize: Mize,
|
mize: Mize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timetrack(mize: &mut Mize) -> MizeResult<()> {
|
pub fn part_timetrack(mize: &mut Mize) -> MizeResult<()> {
|
||||||
#[cfg(feature = "target-os")] {
|
#[cfg(feature = "target-os")] {
|
||||||
let mut cli = mize.get_part_native::<crate::CliPart>("cli")?;
|
let mut cli = mize.get_part_native::<crate::CliPart>("cli")?;
|
||||||
cli.set_command("ppc");
|
cli.set_command("sci");
|
||||||
|
|
||||||
cli.subcommand(
|
cli.subcommand(
|
||||||
Command::new("editActionList").alias("aal").arg(
|
Command::new("editActionList").alias("aal").arg(
|
||||||
@@ -271,7 +271,7 @@ fn command_edit_action_list(matches: &ArgMatches, mut mize: Mize) -> MizeResult<
|
|||||||
.map_err(|e| mize_err!("Failed to write temp file: {}", e))?;
|
.map_err(|e| mize_err!("Failed to write temp file: {}", e))?;
|
||||||
|
|
||||||
// open $EDITOR blocking
|
// open $EDITOR blocking
|
||||||
crate::cli_spawn(format!("nvim {}", tmp_file.display()))?;
|
crate::cli_spawn(&mut mize, format!("nvim {}", tmp_file.display()))?;
|
||||||
|
|
||||||
// read file and update db
|
// read file and update db
|
||||||
let new_file_content = std::fs::read_to_string(&tmp_file)
|
let new_file_content = std::fs::read_to_string(&tmp_file)
|
||||||
@@ -381,7 +381,7 @@ fn command_edit_activities(_: &ArgMatches, mut mize: Mize) -> MizeResult<()> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
// open $EDITOR blocking
|
// open $EDITOR blocking
|
||||||
crate::cli_spawn(format!("nvim {}", tmp_file.display()))?;
|
crate::cli_spawn(&mut mize, format!("nvim {}", tmp_file.display()))?;
|
||||||
|
|
||||||
let new_file_content = std::fs::read_to_string(&tmp_file)
|
let new_file_content = std::fs::read_to_string(&tmp_file)
|
||||||
.map_err(|e| mize_err!("Failed to read temp file: {}", e))?;
|
.map_err(|e| mize_err!("Failed to read temp file: {}", e))?;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ thread_local! {
|
|||||||
macro_rules! out {
|
macro_rules! out {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
// format_args! handles string interpolation safely at compile time
|
// format_args! handles string interpolation safely at compile time
|
||||||
if let Err(e) = $crate::write_to_stdout(format_args!($($arg)*)) {
|
if let Err(e) = $crate::write_to_mize_stdout(format_args!($($arg)*)) {
|
||||||
// Choose your error handling behavior here (panic, print to stderr, or ignore)
|
// Choose your error handling behavior here (panic, print to stderr, or ignore)
|
||||||
eprintln!("out! macro failed to write!!");
|
eprintln!("out! macro failed to write!!");
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ pub fn out_macro_stdout() -> MizeResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_stdout(args: std::fmt::Arguments) -> MizeResult<()> {
|
pub fn write_to_mize_stdout(args: std::fmt::Arguments) -> MizeResult<()> {
|
||||||
MIZE_STDOUT.with(|stdout| {
|
MIZE_STDOUT.with(|stdout| {
|
||||||
if let Some(fun) = stdout.borrow().as_ref() {
|
if let Some(fun) = stdout.borrow().as_ref() {
|
||||||
fun(format!("{}", args));
|
fun(format!("{}", args));
|
||||||
|
|||||||
Reference in New Issue
Block a user