more documentation

This commit is contained in:
Andrei Stoica 2024-04-10 13:21:45 -04:00
parent c92bb3b31b
commit 7453bb8cae
2 changed files with 14 additions and 5 deletions

View File

@ -5,7 +5,6 @@ use chrono::Datelike;
use comrak::nodes::{AstNode, NodeValue}; use comrak::nodes::{AstNode, NodeValue};
use comrak::parse_document; use comrak::parse_document;
use comrak::{Arena, ComrakExtensionOptions, ComrakOptions, ComrakParseOptions}; use comrak::{Arena, ComrakExtensionOptions, ComrakOptions, ComrakParseOptions};
use log;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::{read, File}; use std::fs::{read, File};
use std::io::Write; use std::io::Write;
@ -25,8 +24,9 @@ pub fn get_filepath(data_dir: &PathBuf, date: &NaiveDate) -> PathBuf {
file_path file_path
} }
// generate strings from TaskGroups and date /// generate strings from TaskGroups and date
pub fn generate_file_content(data: &Vec<TaskGroup>, date: &NaiveDate) -> String { pub fn generate_file_content(data: &Vec<TaskGroup>, date: &NaiveDate) -> String {
// TODO: This should be a type and then I can implement it with From<>
let mut content = format!( let mut content = format!(
"# Today's tasks {}-{:02}-{:02}\n", "# Today's tasks {}-{:02}-{:02}\n",
date.year(), date.year(),
@ -46,6 +46,7 @@ pub fn write_file(path: &PathBuf, content: &String) {
/// Load in text file as String /// Load in text file as String
pub fn load_file(file: &TodoFile) -> String { pub fn load_file(file: &TodoFile) -> String {
// TODO: This could be a TryFrom<>
let contents_utf8 = read(file.file.clone()) let contents_utf8 = read(file.file.clone())
.expect(format!("Could not read file {}", file.file.to_string_lossy()).as_str()); .expect(format!("Could not read file {}", file.file.to_string_lossy()).as_str());
str::from_utf8(&contents_utf8) str::from_utf8(&contents_utf8)

View File

@ -19,6 +19,7 @@ use std::path::Path;
use std::process::Command; use std::process::Command;
use todo::{File as TodoFile, TaskGroup}; use todo::{File as TodoFile, TaskGroup};
// TODO: add options to use specific date instead of args.previous
fn main() { fn main() {
// setup // setup
let args = Args::parse(); let args = Args::parse();
@ -100,11 +101,18 @@ fn main() {
let closest_files = TodoFile::get_closest_files(files.collect(), target, args.number); let closest_files = TodoFile::get_closest_files(files.collect(), target, args.number);
// list files // list files
if args.list { if args.list {
closest_files println!("Today - n\tFile");
.into_iter() closest_files.into_iter().for_each(|f| {
.for_each(|f| println!("{}", f.file.canonicalize().unwrap().to_string_lossy())); println!(
"{}\t\t{}",
(today - f.date).num_days(),
f.file.canonicalize().unwrap().to_string_lossy(),
)
});
return (); 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 latest_file = closest_files.first();
let current_file = match latest_file { let current_file = match latest_file {