From 5193cda456143357c95750c3801105a20297c527 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Tue, 2 Nov 2021 02:55:09 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20Use=20semver=20version=20comparison=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 35 ++++++++++++++++++++++++++++------- Cargo.toml | 2 +- src/app.rs | 18 +++++++----------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d41022..a49581e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -871,6 +871,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c64630dcdd71f1a64c435f54885086a0de5d6a12d104d69b165fb7d5286d677" + [[package]] name = "miniz_oxide" version = "0.4.4" @@ -925,6 +931,17 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nom" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" +dependencies = [ + "memchr", + "minimal-lexical", + "version_check", +] + [[package]] name = "ntapi" version = "0.3.6" @@ -1412,7 +1429,7 @@ dependencies = [ "unicode-truncate", "unicode-width", "uuid", - "version-compare", + "versions", ] [[package]] @@ -1525,18 +1542,22 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "versions" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cd9a7a22c45daf5aeb6bea3dff4ecbb8eb43e492582d467b18ce2979b512cbe" +dependencies = [ + "itertools", + "nom", +] + [[package]] name = "waker-fn" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index e48d75c..acbc11b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +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" +versions = "3" [package.metadata.rpm] package = "taskwarrior-tui" diff --git a/src/app.rs b/src/app.rs index 837c11b..8f66a53 100644 --- a/src/app.rs +++ b/src/app.rs @@ -78,12 +78,13 @@ use std::borrow::Borrow; use std::time::Instant; use task_hookrs::project::Project; -use version_compare::{Cmp, Version}; +use versions::Versioning; const MAX_LINE: usize = 4096; lazy_static! { static ref START_TIME: Instant = Instant::now(); + static ref LATEST_TASKWARRIOR_VERSION: Versioning = Versioning::new("2.6.0").unwrap(); } #[derive(Debug)] @@ -205,7 +206,7 @@ pub struct TaskwarriorTui { pub report: String, pub projects: ProjectsState, pub contexts: ContextsState, - pub task_version: String, + pub task_version: Versioning, } impl TaskwarriorTui { @@ -239,11 +240,8 @@ impl TaskwarriorTui { .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 task_version = Versioning::new(String::from_utf8_lossy(&output.stdout).trim()).unwrap(); let (w, h) = crossterm::terminal::size()?; @@ -1586,15 +1584,13 @@ impl TaskwarriorTui { task.arg("rc.json.array=on"); task.arg("rc.confirmation=off"); - if Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() { + if self.task_version >= *LATEST_TASKWARRIOR_VERSION { task.arg(format!("'{}'", self.filter.as_str().trim())); } else { task.arg(self.filter.as_str().trim()); } - if !self.current_context_filter.is_empty() - && Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() - { + if !self.current_context_filter.is_empty() && self.task_version >= *LATEST_TASKWARRIOR_VERSION { task.arg(format!("'{}'", self.current_context_filter.trim())); } else if !self.current_context_filter.is_empty() { task.arg(format!("'\\({}\\)'", self.current_context_filter)); @@ -1602,7 +1598,7 @@ impl TaskwarriorTui { task.arg("export"); - if Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() { + if self.task_version >= *LATEST_TASKWARRIOR_VERSION { task.arg(&self.report); }