aboutsummaryrefslogtreecommitdiff
path: root/src/update.rs
diff options
context:
space:
mode:
authorGolden-Pigeon <goldenpigeon2000@gmail.com>2026-05-22 02:39:02 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-22 02:43:30 +0300
commit1daf54ecbf960c42d612ed4ad2764045a606fb30 (patch)
treec6ee19c7e8032ac77f5c00bc17bc6a1bd93d2272 /src/update.rs
parent0148c1379b76c5c0a9d05588c07dcb06ec32f93f (diff)
feat: show named session command hints
refs #199
Diffstat (limited to 'src/update.rs')
-rw-r--r--src/update.rs61
1 files changed, 51 insertions, 10 deletions
diff --git a/src/update.rs b/src/update.rs
index 98943424..f37a9265 100644
--- a/src/update.rs
+++ b/src/update.rs
@@ -462,8 +462,9 @@ fn prompt_to_stop_server_before_update(
if !io::stdin().is_terminal() {
if requires_stop {
return Err(format!(
- "a herdr server is running and updating to v{} requires stopping it; run `herdr server stop`, then run `herdr update` again",
- release.version
+ "a herdr server is running and updating to v{} requires stopping it; run `{}`, then run `herdr update` again",
+ release.version,
+ crate::session::local_stop_command()
));
}
@@ -533,10 +534,10 @@ fn plan_running_server_update(
) -> Result<Option<RunningServerUpdatePlan>, String> {
let Some(server) = read_running_server_info()? else {
if client_protocol_server_is_running() {
- return Err(
- "a herdr server is listening, but its status API is unavailable; try `herdr server stop`, or stop the old server process manually, then run `herdr update` again"
- .to_string(),
- );
+ return Err(format!(
+ "a herdr server is listening, but its status API is unavailable; try `{}`, or stop the old server process manually, then run `herdr update` again",
+ crate::session::local_stop_command()
+ ));
}
return Ok(None);
};
@@ -560,10 +561,10 @@ fn stop_running_server_for_update(
prompt_to_stop_server_before_update(&plan.server, release, plan.requires_stop)?;
if !stop_server {
if plan.requires_stop {
- return Err(
- "update cancelled; stop the running herdr server with `herdr server stop`, then run `herdr update` again"
- .to_string(),
- );
+ return Err(format!(
+ "update cancelled; stop the running herdr server with `{}`, then run `herdr update` again",
+ crate::session::local_stop_command()
+ ));
}
return Ok(false);
}
@@ -1185,8 +1186,14 @@ mod tests {
atomic::{AtomicBool, Ordering},
Arc,
};
+ use std::sync::{Mutex, OnceLock};
use std::thread;
+ fn env_lock() -> &'static Mutex<()> {
+ static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+ LOCK.get_or_init(|| Mutex::new(()))
+ }
+
fn unique_test_socket_path(name: &str) -> std::path::PathBuf {
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
@@ -1356,6 +1363,40 @@ mod tests {
}
#[test]
+ fn noninteractive_update_requires_stop_names_session_stop_command() {
+ let _guard = env_lock().lock().unwrap();
+ assert!(
+ !io::stdin().is_terminal(),
+ "this test relies on noninteractive test stdin"
+ );
+ std::env::set_var(crate::session::SESSION_ENV_VAR, "work");
+ crate::session::clear_explicit_session_for_test();
+ let server = crate::api::RuntimeStatus {
+ version: Some("0.5.5".to_string()),
+ protocol: Some(2),
+ };
+ let release = ReleaseInfo {
+ version: Version::parse("0.5.6").unwrap(),
+ target_protocol: Some(3),
+ download_url: "https://example.com/herdr".to_string(),
+ notes_body: "### Changed\n- One".to_string(),
+ };
+
+ let err = prompt_to_stop_server_before_update(&server, &release, true).unwrap_err();
+
+ assert!(
+ err.contains("run `herdr session stop work`"),
+ "unexpected error: {err}"
+ );
+ assert!(
+ err.contains("then run `herdr update` again"),
+ "unexpected error: {err}"
+ );
+ std::env::remove_var(crate::session::SESSION_ENV_VAR);
+ crate::session::clear_explicit_session_for_test();
+ }
+
+ #[test]
fn client_protocol_server_is_running_at_detects_live_socket() {
let socket_path = unique_test_socket_path("client-live");
let listener = UnixListener::bind(&socket_path).unwrap();