mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Treat priority as an arbitrary string
This matches what TaskWarrior does: priority is a UDA, and can be redefined by the user's local config.
This commit is contained in:
parent
0dd2d9cd30
commit
1b586a425f
6 changed files with 31 additions and 62 deletions
|
@ -63,7 +63,7 @@ pub use errors::Error;
|
|||
pub use replica::Replica;
|
||||
pub use server::{Server, ServerConfig};
|
||||
pub use storage::StorageConfig;
|
||||
pub use task::{Annotation, Priority, Status, Tag, Task, TaskMut};
|
||||
pub use task::{Annotation, Status, Tag, Task, TaskMut};
|
||||
pub use workingset::WorkingSet;
|
||||
|
||||
/// Re-exported type from the `uuid` crate, for ease of compatibility for consumers of this crate.
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
use chrono::prelude::*;
|
||||
|
||||
mod annotation;
|
||||
mod priority;
|
||||
mod status;
|
||||
mod tag;
|
||||
mod task;
|
||||
|
||||
pub use annotation::Annotation;
|
||||
pub use priority::Priority;
|
||||
pub use status::Status;
|
||||
pub use tag::Tag;
|
||||
pub use task::{Task, TaskMut};
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/// The priority of a task
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Priority {
|
||||
/// Low
|
||||
L,
|
||||
/// Medium
|
||||
M,
|
||||
/// High
|
||||
H,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Priority {
|
||||
/// Get a Priority from the 1-character value in a TaskMap,
|
||||
/// defaulting to M
|
||||
pub(crate) fn from_taskmap(s: &str) -> Priority {
|
||||
match s {
|
||||
"L" => Priority::L,
|
||||
"M" => Priority::M,
|
||||
"H" => Priority::H,
|
||||
_ => Priority::M,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the 1-character value for this priority to use in the TaskMap.
|
||||
pub(crate) fn to_taskmap(&self) -> &str {
|
||||
match self {
|
||||
Priority::L => "L",
|
||||
Priority::M => "M",
|
||||
Priority::H => "H",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_priority() {
|
||||
assert_eq!(Priority::L.to_taskmap(), "L");
|
||||
assert_eq!(Priority::M.to_taskmap(), "M");
|
||||
assert_eq!(Priority::H.to_taskmap(), "H");
|
||||
assert_eq!(Priority::from_taskmap("L"), Priority::L);
|
||||
assert_eq!(Priority::from_taskmap("M"), Priority::M);
|
||||
assert_eq!(Priority::from_taskmap("H"), Priority::H);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use super::tag::{SyntheticTag, TagInner};
|
||||
use super::{Annotation, Priority, Status, Tag, Timestamp};
|
||||
use super::{Annotation, Status, Tag, Timestamp};
|
||||
use crate::depmap::DependencyMap;
|
||||
use crate::replica::Replica;
|
||||
use crate::storage::TaskMap;
|
||||
|
@ -66,6 +66,7 @@ enum Prop {
|
|||
Modified,
|
||||
Start,
|
||||
Status,
|
||||
Priority,
|
||||
Wait,
|
||||
End,
|
||||
Entry,
|
||||
|
@ -138,11 +139,11 @@ impl Task {
|
|||
self.get_timestamp(Prop::Entry.as_ref())
|
||||
}
|
||||
|
||||
pub fn get_priority(&self) -> Priority {
|
||||
pub fn get_priority(&self) -> &str {
|
||||
self.taskmap
|
||||
.get(Prop::Status.as_ref())
|
||||
.map(|s| Priority::from_taskmap(s))
|
||||
.unwrap_or(Priority::M)
|
||||
.get(Prop::Priority.as_ref())
|
||||
.map(|s| s.as_ref())
|
||||
.unwrap_or("")
|
||||
}
|
||||
|
||||
/// Get the wait time. If this value is set, it will be returned, even
|
||||
|
@ -347,6 +348,10 @@ impl<'r> TaskMut<'r> {
|
|||
self.set_string(Prop::Description.as_ref(), Some(description))
|
||||
}
|
||||
|
||||
pub fn set_priority(&mut self, priority: String) -> anyhow::Result<()> {
|
||||
self.set_string(Prop::Priority.as_ref(), Some(priority))
|
||||
}
|
||||
|
||||
pub fn set_entry(&mut self, entry: Option<DateTime<Utc>>) -> anyhow::Result<()> {
|
||||
self.set_timestamp(Prop::Entry.as_ref(), entry)
|
||||
}
|
||||
|
@ -725,6 +730,12 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_priority_default() {
|
||||
let task = Task::new(Uuid::new_v4(), TaskMap::new(), dm());
|
||||
assert_eq!(task.get_priority(), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_annotations() {
|
||||
let task = Task::new(
|
||||
|
@ -810,6 +821,15 @@ mod test {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_get_priority() {
|
||||
with_mut_task(|mut task| {
|
||||
assert_eq!(task.get_priority(), "");
|
||||
task.set_priority("H".into()).unwrap();
|
||||
assert_eq!(task.get_priority(), "H");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_status_pending() {
|
||||
with_mut_task(|mut task| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue