summaryrefslogtreecommitdiff
path: root/crates/vcs_actions/src/actions.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-12-24 16:12:46 +0800
committer魏曹先生 <1992414357@qq.com>2025-12-24 16:12:46 +0800
commitca29e7b2152260059417c142641cd19ddbb512c4 (patch)
tree8927915b3cc5229e6cd503e886de33e596d5814c /crates/vcs_actions/src/actions.rs
parent4cccc5d093bed8abbe35689c061486b79c44c558 (diff)
Add local output channel for CLI feedback in track actions
Add `try_get_local_output` helper to retrieve output channel from context and `local_println!` macro for sending formatted strings. Use these in track actions to send progress messages to CLI instead of stdout. Also reduce log level for connection events from info to debug.
Diffstat (limited to 'crates/vcs_actions/src/actions.rs')
-rw-r--r--crates/vcs_actions/src/actions.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/crates/vcs_actions/src/actions.rs b/crates/vcs_actions/src/actions.rs
index d3c0dd6..260a6be 100644
--- a/crates/vcs_actions/src/actions.rs
+++ b/crates/vcs_actions/src/actions.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
use action_system::action::ActionContext;
use cfg_file::config::ConfigFile;
use tcp_connection::{error::TcpTargetError, instance::ConnectionInstance};
-use tokio::sync::Mutex;
+use tokio::sync::{Mutex, mpsc::Sender};
use vcs_data::{
constants::SERVER_PATH_MEMBER_PUB,
data::{
@@ -64,6 +64,16 @@ pub fn try_get_user_directory(ctx: &ActionContext) -> Result<Arc<UserDirectory>,
Ok(user_directory)
}
+/// Try to get the LocalWorkspace instance from the context.
+pub fn try_get_local_output(ctx: &ActionContext) -> Result<Arc<Sender<String>>, TcpTargetError> {
+ let Some(output) = ctx.get_arc::<Sender<String>>() else {
+ return Err(TcpTargetError::NotFound(
+ "Client sender not found".to_string(),
+ ));
+ };
+ Ok(output)
+}
+
/// Authenticate member based on context and return MemberId
pub async fn auth_member(
ctx: &ActionContext,
@@ -196,3 +206,13 @@ macro_rules! write_and_return {
return Ok($result);
}};
}
+
+/// The macro to send formatted string to output channel.
+/// Usage: local_println!(output, "format string", arg1, arg2, ...)
+#[macro_export]
+macro_rules! local_println {
+ ($output:expr, $($arg:tt)*) => {{
+ let formatted = format!($($arg)*);
+ let _ = $output.send(formatted).await;
+ }};
+}