Compare commits
6 Commits
e389f34bd6
...
6eba05895f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6eba05895f | ||
|
|
5a45cd1410 | ||
|
|
7832d09fe8 | ||
|
|
aa9e032c31 | ||
|
|
b949502869 | ||
|
|
41cab74028 |
85
pttodoer/Cargo.lock
generated
85
pttodoer/Cargo.lock
generated
@@ -180,6 +180,12 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
@@ -298,6 +304,7 @@ dependencies = [
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
"tempdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -309,6 +316,43 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
|
||||
dependencies = [
|
||||
"fuchsia-cprng",
|
||||
"libc",
|
||||
"rand_core 0.3.1",
|
||||
"rdrand",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
dependencies = [
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.4"
|
||||
@@ -338,6 +382,15 @@ version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
@@ -394,6 +447,16 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempdir"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"remove_dir_all",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
@@ -466,6 +529,28 @@ version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
|
||||
@@ -12,3 +12,4 @@ croner = "2.0.4"
|
||||
regex = "1.10.4"
|
||||
serde = { version = "1.0.202", features = [ "serde_derive" ] }
|
||||
serde_yaml = "0.9.34"
|
||||
tempdir = "0.3.7"
|
||||
|
||||
@@ -7,6 +7,7 @@ use regex::Regex;
|
||||
use croner;
|
||||
use clap::Parser;
|
||||
use std::io::Write;
|
||||
use tempdir::TempDir;
|
||||
|
||||
fn main() {
|
||||
let flags = Flags::new();
|
||||
@@ -24,6 +25,10 @@ fn main() {
|
||||
_ => {},
|
||||
};
|
||||
|
||||
if flags.edit {
|
||||
db.edit().expect("failed to edit");
|
||||
}
|
||||
|
||||
db.save(flags.dry_run).expect("failed to save");
|
||||
}
|
||||
|
||||
@@ -110,6 +115,47 @@ impl DB {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn edit(&self) -> Result<(), String> {
|
||||
let d = TempDir::new(&TS::now().to_string()).expect("failed to create a temp dir");
|
||||
for set in &self.0 {
|
||||
let base = set.file.split("/").last().unwrap().to_string();
|
||||
let f = d.path().join(base);
|
||||
set.save_due_as(f.display().to_string())?;
|
||||
}
|
||||
|
||||
//std::process::Command::new("/bin/sh")
|
||||
// .current_dir(d.path())
|
||||
// .arg("-c")
|
||||
// .arg("vim -p ./*")
|
||||
// .spawn()
|
||||
// .expect("failed to start vim")
|
||||
// .wait()
|
||||
// .expect("failed to vim");
|
||||
|
||||
for set in &self.0 {
|
||||
let base = set.file.split("/").last().unwrap().to_string();
|
||||
let f = d.path().join(base);
|
||||
let edited = TasksAndMetadata::new(f.display().to_string());
|
||||
|
||||
let not_due = set.not_due();
|
||||
let was_due = set.due();
|
||||
|
||||
// for each in was_due
|
||||
// if not in edited
|
||||
// not_due.push
|
||||
// due = []
|
||||
// for each in edited
|
||||
// if not due
|
||||
// not_due.push
|
||||
// else
|
||||
// due.push
|
||||
// all = due + not_due // ordered
|
||||
// save to self.0
|
||||
}
|
||||
|
||||
Err("not impl".to_string())
|
||||
}
|
||||
|
||||
pub fn save(&self, dry_run: bool) -> Result<(), String> {
|
||||
for i in &self.0 {
|
||||
i.save(dry_run)?;
|
||||
@@ -147,7 +193,7 @@ mod test_taskss {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TasksAndMetadata {
|
||||
tasks: Tasks,
|
||||
file: String,
|
||||
@@ -167,22 +213,26 @@ impl TasksAndMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn due(&self) -> TasksAndMetadata {
|
||||
let mut cloned = self.clone();
|
||||
cloned.tasks = cloned.tasks.due();
|
||||
cloned
|
||||
}
|
||||
|
||||
pub fn not_due(&self) -> TasksAndMetadata {
|
||||
let mut cloned = self.clone();
|
||||
cloned.tasks = cloned.tasks.not_due();
|
||||
cloned
|
||||
}
|
||||
|
||||
pub fn save(&self, dry_run: bool) -> Result<(), String> {
|
||||
let version = file_version(self.file.clone())?;
|
||||
let mut file = self.file.clone();
|
||||
if version != self.version {
|
||||
file = format!("{}.{}", &self.file, &self.version.to_string());
|
||||
file = format!("{}.{}", &self.file, TS::now().to_string());
|
||||
eprintln!("saving conflicting {} as {}", &self.file, &file);
|
||||
}
|
||||
|
||||
self.save_as(file.clone(), dry_run)?;
|
||||
|
||||
match file == self.file {
|
||||
true => Ok(()),
|
||||
false => Err(format!("{} has been updated", self.file)),
|
||||
}
|
||||
}
|
||||
|
||||
fn save_as(&self, file: String, dry_run: bool) -> Result<(), String> {
|
||||
match dry_run {
|
||||
true => {
|
||||
match &file == &self.file {
|
||||
@@ -192,7 +242,15 @@ impl TasksAndMetadata {
|
||||
eprintln!("{}", self.tasks.to_string());
|
||||
Ok(())
|
||||
},
|
||||
false => {
|
||||
false => self.save_as(file),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_due_as(&self, file: String) -> Result<(), String> {
|
||||
self.due().save_as(file)
|
||||
}
|
||||
|
||||
pub fn save_as(&self, file: String) -> Result<(), String> {
|
||||
match std::fs::File::create(&file) {
|
||||
Ok(mut f) => {
|
||||
match f.write_all(self.tasks.to_string().as_bytes()) {
|
||||
@@ -202,8 +260,6 @@ impl TasksAndMetadata {
|
||||
},
|
||||
Err(msg) => Err(format!("failed to create {}: {}", file, msg)),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//fn debug(&self) -> String {
|
||||
@@ -222,7 +278,7 @@ fn file_version(file: String) -> Result<TS, String> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
|
||||
pub struct Tasks(Vec<Task>);
|
||||
|
||||
impl Tasks {
|
||||
@@ -340,6 +396,14 @@ impl Tasks {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn not_due(&self) -> Tasks {
|
||||
Tasks(self.0.iter()
|
||||
.filter(|x| !x.is_due())
|
||||
.map(|x| x.clone())
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn due(&self) -> Tasks {
|
||||
Tasks(self.0.iter()
|
||||
.filter(|x| x.is_due())
|
||||
@@ -835,8 +899,7 @@ mod test_duration {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
struct TS(u64);
|
||||
|
||||
impl TS {
|
||||
|
||||
Reference in New Issue
Block a user