[pdm-devel] [PATCH yew-comp 3/7] utils: factor out task description into own function
Dominik Csapak
d.csapak at proxmox.com
Mon Jan 20 10:29:53 CET 2025
we'll need this separated from the UPID parsing code, so we can also use
info from e.g. a `PveUpid` that we don't have here (yet).
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/utils.rs | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/utils.rs b/src/utils.rs
index 24de356..d500b6d 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -227,20 +227,22 @@ pub fn init_task_descr_table_base() {
register_task_description("srvreload", (tr!("Service"), tr!("Reload")));
}
+/// Uses information from the given [`UPID`] to render the task description with [`format_task_description`]
pub fn format_upid(upid: &str) -> String {
match upid.parse::<UPID>() {
Err(_) => upid.to_string(),
- Ok(upid) => {
- if let Some(text) =
- lookup_task_description(upid.worker_type.as_str(), upid.worker_id.as_deref())
- {
- text
- } else {
- match (upid.worker_type.as_str(), upid.worker_id) {
- (worker_type, Some(id)) => format!("{} {}", worker_type, id),
- (worker_type, None) => worker_type.to_string(),
- }
- }
+ Ok(upid) => format_task_description(&upid.worker_type, upid.worker_id.as_deref()),
+ }
+}
+
+/// Formats the given worker type and id to a Human readable task description
+pub fn format_task_description(worker_type: &str, worker_id: Option<&str>) -> String {
+ if let Some(text) = lookup_task_description(worker_type, worker_id) {
+ text
+ } else {
+ match worker_id {
+ Some(id) => format!("{} {}", worker_type, id),
+ None => worker_type.to_string(),
}
}
}
--
2.39.5
More information about the pdm-devel
mailing list