Fix: some errors

This commit is contained in:
gaofei 2025-01-14 12:13:55 +08:00
parent ec316d7d0b
commit b2707647d7
3 changed files with 20 additions and 7 deletions

View File

@ -50,7 +50,8 @@ fn time_to_readable(seconds: u64) -> String {
if minutes > 0 { if minutes > 0 {
result.push_str(&format!("{}m ", minutes)); result.push_str(&format!("{}m ", minutes));
} }
if secs > 0 && days == 0 && hours == 0 { // 只在没有天和小时的时候显示秒 if secs > 0 && days == 0 && hours == 0 {
// 只在没有天和小时的时候显示秒
result.push_str(&format!("{}s", secs)); result.push_str(&format!("{}s", secs));
} }

View File

@ -5,7 +5,12 @@ use super::start::start_process;
use super::stop::stop_process; use super::stop::stop_process;
use std::path::PathBuf; use std::path::PathBuf;
pub fn restart_process(config: Option<PathBuf>, namespace: Option<String>, target: Option<String>, args: Vec<String>) { pub fn restart_process(
config: Option<PathBuf>,
namespace: Option<String>,
target: Option<String>,
args: Vec<String>,
) {
let dump_config = DumpConfig::get_instance(); let dump_config = DumpConfig::get_instance();
// 如果指定了target先检查是否是已存在的进程 // 如果指定了target先检查是否是已存在的进程

View File

@ -32,7 +32,7 @@ pub fn start_process(
// 如果指定了target先检查是否是已存在的进程 // 如果指定了target先检查是否是已存在的进程
if let Some(ref target_str) = target { if let Some(ref target_str) = target {
if let Ok(processes) = dump_config.list_processes() { if let Ok(processes) = dump_config.list_processes() {
// 尝试将target解析为pmr_id // 按pmr_id查找进程
if let Ok(pmr_id) = target_str.parse::<u32>() { if let Ok(pmr_id) = target_str.parse::<u32>() {
if let Some(process) = processes.iter().find(|p| p.pmr_id == pmr_id) { if let Some(process) = processes.iter().find(|p| p.pmr_id == pmr_id) {
start_existing_process(process); start_existing_process(process);
@ -40,8 +40,8 @@ pub fn start_process(
} }
} }
// 按名称和namespace查找进程 // 按name查找进程
if let Some(process) = processes.iter().find(|p| p.name == *target_str && p.namespace == namespace) { if let Some(process) = processes.iter().find(|p| p.name == *target_str) {
start_existing_process(process); start_existing_process(process);
return; return;
} }
@ -66,8 +66,14 @@ pub fn start_process(
}); });
if let Ok(processes) = dump_config.list_processes() { if let Ok(processes) = dump_config.list_processes() {
if let Some(_existing) = processes.iter().find(|p| p.name == process_name && p.namespace == namespace) { if let Some(_existing) = processes
println!("\n进程 '{}' 在命名空间 '{}' 中已经存在:", process_name, namespace); .iter()
.find(|p| p.name == process_name && p.namespace == namespace)
{
println!(
"\n进程 '{}' 在命名空间 '{}' 中已经存在:",
process_name, namespace
);
list_processes(false); list_processes(false);
return; return;
} }
@ -131,6 +137,7 @@ pub fn start_process(
args, args,
) )
.expect("无法将进程添加到配置文件"); .expect("无法将进程添加到配置文件");
list_processes(false);
} }
Err(e) => { Err(e) => {
eprintln!("启动进程失败: {}", e); eprintln!("启动进程失败: {}", e);