mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 23:46:41 +02:00
feat: Add task version check ✨
This commit is contained in:
parent
8969992930
commit
561c1fb2a2
3 changed files with 40 additions and 15 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -1412,6 +1412,7 @@ dependencies = [
|
|||
"unicode-truncate",
|
||||
"unicode-width",
|
||||
"uuid",
|
||||
"version-compare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1524,6 +1525,12 @@ version = "0.8.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
|
|
|
@ -43,6 +43,7 @@ unicode-segmentation = "1.8.0"
|
|||
unicode-truncate = "0.2.0"
|
||||
unicode-width = "0.1.8"
|
||||
uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
||||
version-compare = "0.1.0"
|
||||
|
||||
[package.metadata.rpm]
|
||||
package = "taskwarrior-tui"
|
||||
|
|
43
src/app.rs
43
src/app.rs
|
@ -78,6 +78,8 @@ use std::borrow::Borrow;
|
|||
use std::time::Instant;
|
||||
use task_hookrs::project::Project;
|
||||
|
||||
use version_compare::{Cmp, Version};
|
||||
|
||||
const MAX_LINE: usize = 4096;
|
||||
|
||||
lazy_static! {
|
||||
|
@ -203,6 +205,7 @@ pub struct TaskwarriorTui {
|
|||
pub report: String,
|
||||
pub projects: ProjectsState,
|
||||
pub contexts: ContextsState,
|
||||
pub task_version: String,
|
||||
}
|
||||
|
||||
impl TaskwarriorTui {
|
||||
|
@ -231,6 +234,17 @@ impl TaskwarriorTui {
|
|||
let c = Config::new(&data, report)?;
|
||||
let kc = KeyConfig::new(&data)?;
|
||||
|
||||
let output = std::process::Command::new("task")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.context("Unable to run `task --version`")
|
||||
.unwrap();
|
||||
let task_version = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
||||
if Version::from(&task_version).is_none() {
|
||||
return Err(anyhow!("Unable to parse `task --version`.\nGot {}", task_version));
|
||||
}
|
||||
|
||||
let (w, h) = crossterm::terminal::size()?;
|
||||
|
||||
let mut app = Self {
|
||||
|
@ -269,6 +283,7 @@ impl TaskwarriorTui {
|
|||
report: report.to_string(),
|
||||
projects: ProjectsState::new(),
|
||||
contexts: ContextsState::new(),
|
||||
task_version,
|
||||
};
|
||||
|
||||
for c in app.config.filter.chars() {
|
||||
|
@ -1571,28 +1586,30 @@ impl TaskwarriorTui {
|
|||
task.arg("rc.json.array=on");
|
||||
task.arg("rc.confirmation=off");
|
||||
|
||||
let filter = if self.current_context_filter.is_empty() {
|
||||
format!("'{}'", self.filter.as_str())
|
||||
if Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() {
|
||||
task.arg(format!("'{}'", self.filter.as_str().trim()));
|
||||
} else {
|
||||
format!("'{}' '{}'", self.filter.as_str(), self.current_context_filter)
|
||||
};
|
||||
task.arg(self.filter.as_str().trim());
|
||||
}
|
||||
|
||||
match shlex::split(&filter) {
|
||||
Some(cmd) => {
|
||||
for s in cmd {
|
||||
task.arg(&s);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
task.arg("");
|
||||
}
|
||||
if !self.current_context_filter.is_empty()
|
||||
&& Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap()
|
||||
{
|
||||
task.arg(format!("'{}'", self.current_context_filter.trim()));
|
||||
} else if !self.current_context_filter.is_empty() {
|
||||
task.arg(format!("'\\({}\\)'", self.current_context_filter));
|
||||
}
|
||||
|
||||
task.arg("export");
|
||||
|
||||
if Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() {
|
||||
task.arg(&self.report);
|
||||
}
|
||||
|
||||
let output = task.output()?;
|
||||
let data = String::from_utf8_lossy(&output.stdout);
|
||||
let error = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
if !error.contains("The expression could not be evaluated.") {
|
||||
if let Ok(imported) = import(data.as_bytes()) {
|
||||
self.tasks = imported;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue