mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Summarize tasks nicely in console output
This commit is contained in:
parent
adfde8be15
commit
9e3646bf84
3 changed files with 20 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
use crate::argparse::{Filter, Modification};
|
use crate::argparse::{Filter, Modification};
|
||||||
use crate::invocation::{apply_modification, filtered_tasks};
|
use crate::invocation::{apply_modification, filtered_tasks, summarize_task};
|
||||||
use taskchampion::Replica;
|
use taskchampion::Replica;
|
||||||
use termcolor::WriteColor;
|
use termcolor::WriteColor;
|
||||||
|
|
||||||
|
@ -12,7 +12,11 @@ pub(crate) fn execute<W: WriteColor>(
|
||||||
for task in filtered_tasks(replica, &filter)? {
|
for task in filtered_tasks(replica, &filter)? {
|
||||||
let mut task = task.into_mut(replica);
|
let mut task = task.into_mut(replica);
|
||||||
|
|
||||||
apply_modification(w, &mut task, &modification)?;
|
apply_modification(&mut task, &modification)?;
|
||||||
|
|
||||||
|
let task = task.into_immut();
|
||||||
|
let summary = summarize_task(replica, &task)?;
|
||||||
|
writeln!(w, "modified task {}", summary)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -51,7 +55,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
w.into_string(),
|
w.into_string(),
|
||||||
format!("modified task {}\n", task.get_uuid())
|
format!("modified task 1 - new description\n")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::argparse::{Command, Subcommand};
|
use crate::argparse::{Command, Subcommand};
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use taskchampion::{Replica, Server, ServerConfig, StorageConfig, Uuid};
|
use taskchampion::{Replica, Server, ServerConfig, StorageConfig, Task, Uuid};
|
||||||
use termcolor::{ColorChoice, StandardStream};
|
use termcolor::{ColorChoice, StandardStream};
|
||||||
|
|
||||||
mod cmd;
|
mod cmd;
|
||||||
|
@ -149,3 +149,14 @@ fn get_writer() -> StandardStream {
|
||||||
ColorChoice::Never
|
ColorChoice::Never
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Summarize a task in a single line
|
||||||
|
fn summarize_task(replica: &mut Replica, task: &Task) -> anyhow::Result<String> {
|
||||||
|
let ws = replica.working_set()?;
|
||||||
|
let uuid = task.get_uuid();
|
||||||
|
if let Some(id) = ws.by_uuid(uuid) {
|
||||||
|
Ok(format!("{} - {}", id, task.get_description()))
|
||||||
|
} else {
|
||||||
|
Ok(format!("{} - {}", uuid, task.get_description()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
use crate::argparse::{DescriptionMod, Modification};
|
use crate::argparse::{DescriptionMod, Modification};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use taskchampion::TaskMut;
|
use taskchampion::TaskMut;
|
||||||
use termcolor::WriteColor;
|
|
||||||
|
|
||||||
/// Apply the given modification
|
/// Apply the given modification
|
||||||
pub(super) fn apply_modification<W: WriteColor>(
|
pub(super) fn apply_modification(
|
||||||
w: &mut W,
|
|
||||||
task: &mut TaskMut,
|
task: &mut TaskMut,
|
||||||
modification: &Modification,
|
modification: &Modification,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
@ -42,7 +40,5 @@ pub(super) fn apply_modification<W: WriteColor>(
|
||||||
task.remove_tag(&tag)?;
|
task.remove_tag(&tag)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(w, "modified task {}", task.get_uuid())?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue