timetrack works locally
This commit is contained in:
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::{path::PathBuf, thread};
|
||||
use tracing::info;
|
||||
use tracing::{info, warn};
|
||||
|
||||
// console_log macro
|
||||
// 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");
|
||||
|
||||
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)
|
||||
let content = std::fs::read_to_string(&file_path).unwrap_or_default();
|
||||
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| {
|
||||
if let Some(spawn) = cell.borrow().as_ref() {
|
||||
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,
|
||||
spawn_wait_rx: flume::Receiver<()>,
|
||||
) -> MizeResult<()> {
|
||||
let binding = msg.data()?;
|
||||
let data = binding
|
||||
let tmp = msg.data()?;
|
||||
let data = tmp
|
||||
.cbor()
|
||||
.as_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);
|
||||
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,
|
||||
}
|
||||
|
||||
pub fn timetrack(mize: &mut Mize) -> MizeResult<()> {
|
||||
pub fn part_timetrack(mize: &mut Mize) -> MizeResult<()> {
|
||||
#[cfg(feature = "target-os")] {
|
||||
let mut cli = mize.get_part_native::<crate::CliPart>("cli")?;
|
||||
cli.set_command("ppc");
|
||||
cli.set_command("sci");
|
||||
|
||||
cli.subcommand(
|
||||
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))?;
|
||||
|
||||
// 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
|
||||
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 {
|
||||
// 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)
|
||||
.map_err(|e| mize_err!("Failed to read temp file: {}", e))?;
|
||||
|
||||
Reference in New Issue
Block a user