diff --git a/src/db.rs b/src/db.rs index 1f4305879d6118455297e3f8a4ea8bc5464b753e..ebecf6233dc3d09ab8dc67f30082ab567cc8e1ec 100644 --- a/src/db.rs +++ b/src/db.rs @@ -143,7 +143,17 @@ impl TaskId { } pub fn short(&self) -> String { - self.0[self.0.len() - 7..].to_string() + format!("td-{}", &self.0[self.0.len() - 7..]) + } + + /// Return a display-friendly short ID from a raw ULID string. + pub fn display_id(raw: &str) -> String { + let n = raw.len(); + if n > 7 { + format!("td-{}", &raw[n - 7..]) + } else { + format!("td-{raw}") + } } } @@ -539,6 +549,8 @@ pub fn list_projects() -> Result> { } pub fn resolve_task_id(store: &Store, raw: &str, include_deleted: bool) -> Result { + let raw = raw.strip_prefix("td-").unwrap_or(raw); + if let Ok(id) = TaskId::parse(raw) { if store.get_task(&id, include_deleted)?.is_some() { return Ok(id); diff --git a/tests/cli_dep.rs b/tests/cli_dep.rs index b9026833167a6e2cf26758ea4f7da4ccb4a05e8b..91d5f01f13abebc8f880f54873281dbc26b089bd 100644 --- a/tests/cli_dep.rs +++ b/tests/cli_dep.rs @@ -221,7 +221,7 @@ fn dep_add_rejects_nonexistent_child() { .current_dir(&tmp) .assert() .failure() - .stderr(predicate::str::contains("task 'td-ghost' not found")); + .stderr(predicate::str::contains("task 'ghost' not found")); } #[test] @@ -234,5 +234,5 @@ fn dep_add_rejects_nonexistent_parent() { .current_dir(&tmp) .assert() .failure() - .stderr(predicate::str::contains("task 'td-phantom' not found")); + .stderr(predicate::str::contains("task 'phantom' not found")); } diff --git a/tests/cli_log.rs b/tests/cli_log.rs index 315c81855ce49b370cbfb6cc55b6d8439deccc6b..f98dd8d147f141da61ed7fe604d664b69d8f4db3 100644 --- a/tests/cli_log.rs +++ b/tests/cli_log.rs @@ -39,7 +39,7 @@ fn log_human_reports_task_id() { .assert() .success() .stdout(predicate::str::contains(format!( - "logged to {}", + "logged to td-{}", &id[id.len() - 7..] ))); } @@ -70,7 +70,7 @@ fn log_nonexistent_task_fails() { .current_dir(&tmp) .assert() .failure() - .stderr(predicate::str::contains("task 'td-nope' not found")); + .stderr(predicate::str::contains("task 'nope' not found")); } #[test]