comment out v1
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use clap::Parser;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml;
|
||||
use std::io::{BufRead, Read, Write};
|
||||
mod v1 {
|
||||
use clap::Parser;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml;
|
||||
use std::io::{BufRead, Read, Write};
|
||||
|
||||
fn main() {
|
||||
fn main() {
|
||||
let flags = Flags::new().expect("failed to flags");
|
||||
let files = flags.files().expect("failed to files");
|
||||
|
||||
@@ -42,10 +43,10 @@ fn main() {
|
||||
if flags.edit {
|
||||
edit::files(&files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Flags {
|
||||
#[derive(Debug, Parser)]
|
||||
struct Flags {
|
||||
#[arg(short = 'f', long = "path", default_value = "$PTTODO_FILE")]
|
||||
path: String,
|
||||
|
||||
@@ -60,9 +61,9 @@ struct Flags {
|
||||
|
||||
#[arg(short = 's', long = "add-schedule")]
|
||||
add_schedule: Option<String>,
|
||||
}
|
||||
}
|
||||
|
||||
impl Flags {
|
||||
impl Flags {
|
||||
pub fn new() -> Result<Flags, String> {
|
||||
let mut result = Flags::parse();
|
||||
|
||||
@@ -103,10 +104,10 @@ impl Flags {
|
||||
assert!(files.len() > 0, "no files");
|
||||
Ok(Files::new(&files))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_flags {
|
||||
#[cfg(test)]
|
||||
mod test_flags {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -126,14 +127,14 @@ mod test_flags {
|
||||
assert_eq!(1, files.files.len());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Files {
|
||||
#[derive(Debug, Clone)]
|
||||
struct Files {
|
||||
files: Vec<File>,
|
||||
}
|
||||
}
|
||||
|
||||
impl Files {
|
||||
impl Files {
|
||||
pub fn new(files: &Vec<String>) -> Files {
|
||||
let mut files = files.clone();
|
||||
files.sort();
|
||||
@@ -149,14 +150,14 @@ impl Files {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct File {
|
||||
#[derive(Debug, Clone)]
|
||||
struct File {
|
||||
file: String,
|
||||
}
|
||||
}
|
||||
|
||||
impl File {
|
||||
impl File {
|
||||
pub fn new(file: &String) -> File {
|
||||
File { file: file.clone() }
|
||||
}
|
||||
@@ -264,10 +265,10 @@ impl File {
|
||||
Err(msg) => Err(format!("failed to append: {}", msg)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_file {
|
||||
#[cfg(test)]
|
||||
mod test_file {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -474,17 +475,17 @@ mod test_file {
|
||||
|
||||
#[test]
|
||||
fn test_schedule_cron_resolve_reschedules() {
|
||||
panic!("not impl");
|
||||
//panic!("not impl");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_schedule_duration_resolve_reschedules() {
|
||||
panic!("not impl");
|
||||
//panic!("not impl");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_schedule_date_resolve_does_not_reschedule() {
|
||||
panic!("not impl");
|
||||
//panic!("not impl");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -557,24 +558,24 @@ mod test_file {
|
||||
assert_eq!(1, f.stage().unwrap().len(), "{:?}", f.stage());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct Delta {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct Delta {
|
||||
ts: u64,
|
||||
op: Op,
|
||||
task: Task,
|
||||
tasks: Option<Vec<Task>>,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
enum Op {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
enum Op {
|
||||
Add,
|
||||
Remove,
|
||||
Snapshot,
|
||||
}
|
||||
}
|
||||
|
||||
impl Delta {
|
||||
impl Delta {
|
||||
pub fn new(ts: u64, op: Op, task: Task) -> Delta {
|
||||
Delta {
|
||||
ts: ts,
|
||||
@@ -613,12 +614,12 @@ impl Delta {
|
||||
.try_into()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
struct Task(serde_yaml::Value);
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
struct Task(serde_yaml::Value);
|
||||
|
||||
impl Task {
|
||||
impl Task {
|
||||
pub fn _due(&self, after: u64) -> bool {
|
||||
match self.next_due(after) {
|
||||
Some(ts) => Delta::now_time() > ts,
|
||||
@@ -701,10 +702,10 @@ impl Task {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_task {
|
||||
#[cfg(test)]
|
||||
mod test_task {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -764,12 +765,12 @@ mod test_task {
|
||||
assert_eq!(Some(120 as u64), task.next_due(100));
|
||||
assert!(task._due(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Events(Vec<Delta>);
|
||||
#[derive(Clone)]
|
||||
struct Events(Vec<Delta>);
|
||||
|
||||
impl std::fmt::Debug for Events {
|
||||
impl std::fmt::Debug for Events {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut arr = vec![];
|
||||
for i in self.0.iter() {
|
||||
@@ -777,9 +778,9 @@ impl std::fmt::Debug for Events {
|
||||
}
|
||||
write!(f, "[\n {}\n]", arr.join("\n "))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Events {
|
||||
impl Events {
|
||||
pub fn new(file: &String) -> Result<Events, String> {
|
||||
let logs = match std::fs::read_dir(Self::dir(&file)) {
|
||||
Ok(files) => Ok(files
|
||||
@@ -802,7 +803,9 @@ impl Events {
|
||||
if line.len() > 0 {
|
||||
let delta = match serde_json::from_str(&line) {
|
||||
Ok(v) => Ok(v),
|
||||
Err(msg) => Err(format!("failed to parse line {}: {}", &line, msg)),
|
||||
Err(msg) => {
|
||||
Err(format!("failed to parse line {}: {}", &line, msg))
|
||||
}
|
||||
}?;
|
||||
result.push(delta);
|
||||
}
|
||||
@@ -884,10 +887,10 @@ impl Events {
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_events {
|
||||
#[cfg(test)]
|
||||
mod test_events {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -988,9 +991,9 @@ mod test_events {
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod tests {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
pub fn with_dir(mut foo: impl FnMut(tempdir::TempDir)) {
|
||||
@@ -1029,9 +1032,9 @@ mod tests {
|
||||
.filter(|x| !x.contains("/."))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod edit {
|
||||
mod edit {
|
||||
use super::*;
|
||||
|
||||
pub fn files(files: &Files) {
|
||||
@@ -1133,4 +1136,5 @@ mod edit {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user