From 7453bb8cae92d4b32d25b062f71ddccb4468eeda Mon Sep 17 00:00:00 2001 From: Andrei Stoica Date: Wed, 10 Apr 2024 13:21:45 -0400 Subject: [PATCH] more documentation --- src/file/mod.rs | 5 +++-- src/main.rs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/file/mod.rs b/src/file/mod.rs index 80487ed..868e23d 100644 --- a/src/file/mod.rs +++ b/src/file/mod.rs @@ -5,7 +5,6 @@ use chrono::Datelike; use comrak::nodes::{AstNode, NodeValue}; use comrak::parse_document; use comrak::{Arena, ComrakExtensionOptions, ComrakOptions, ComrakParseOptions}; -use log; use std::collections::HashMap; use std::fs::{read, File}; use std::io::Write; @@ -25,8 +24,9 @@ pub fn get_filepath(data_dir: &PathBuf, date: &NaiveDate) -> PathBuf { file_path } -// generate strings from TaskGroups and date +/// generate strings from TaskGroups and date pub fn generate_file_content(data: &Vec, date: &NaiveDate) -> String { + // TODO: This should be a type and then I can implement it with From<> let mut content = format!( "# Today's tasks {}-{:02}-{:02}\n", date.year(), @@ -46,6 +46,7 @@ pub fn write_file(path: &PathBuf, content: &String) { /// Load in text file as String pub fn load_file(file: &TodoFile) -> String { + // TODO: This could be a TryFrom<> let contents_utf8 = read(file.file.clone()) .expect(format!("Could not read file {}", file.file.to_string_lossy()).as_str()); str::from_utf8(&contents_utf8) diff --git a/src/main.rs b/src/main.rs index ad17a16..2def14c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ use std::path::Path; use std::process::Command; use todo::{File as TodoFile, TaskGroup}; +// TODO: add options to use specific date instead of args.previous fn main() { // setup let args = Args::parse(); @@ -100,11 +101,18 @@ fn main() { let closest_files = TodoFile::get_closest_files(files.collect(), target, args.number); // list files if args.list { - closest_files - .into_iter() - .for_each(|f| println!("{}", f.file.canonicalize().unwrap().to_string_lossy())); + println!("Today - n\tFile"); + closest_files.into_iter().for_each(|f| { + println!( + "{}\t\t{}", + (today - f.date).num_days(), + f.file.canonicalize().unwrap().to_string_lossy(), + ) + }); return (); } + // TODO: If the user did not pick a date that exist they should have the + // option to updated their choice let latest_file = closest_files.first(); let current_file = match latest_file {