summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs71
1 files changed, 45 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs
index 6dfb441..49c8152 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,37 +1,56 @@
-use std::fs::File;
-use std::io::prelude::*;
-use std::path::Path;
+use std::env;
+use chrono::{Local, Duration};
mod task;
+use task::*;
mod parse;
use parse::*;
mod html_calendar;
use html_calendar::*;
+mod dates;
+use dates::*;
-// https://doc.rust-lang.org/std/fs/struct.File.html
-fn main() {
- let path = Path::new("wtd.md");
- let display = path.display();
+fn command_html() {
+ /* Pull tasks from:
+ * - wtd.md (always, assuming exists)
+ * - [week].md (assuming exists)
+ * - weekly.md (only included for weeks without a week.md)
+ */
+ let n_days = 14;
+ let first_date = Local::now().date().naive_local();
+ let last_date = first_date + Duration::days(n_days - 1); // inclusive
+ let paths = relevant_files(&first_date, &last_date);
+ let mut tasks: Vec<Task> = vec![];
+ for path in paths {
+ tasks.append(&mut tasks_from_path(&path));
+ }
+
+ tasks_to_html_file(&tasks, CalendarPrivacy::Public, &"public.html");
+ tasks_to_html_file(&tasks, CalendarPrivacy::Private, &"private.html");
+}
+
+fn command_describe(week: &str) {
+ // TODO
+}
+
+fn command_generate(week: &str) {
+ // TODO
+}
- // Open the path in read-only mode, returns `io::Result<File>`
- let mut file = match File::open(&path) {
- Err(why) => panic!("Error opening {}: {}", display, why),
- Ok(file) => file,
- };
+fn command_validate() {
+ // TODO
+}
- // Read the file contents into a string, returns `io::Result<usize>`
- let mut s = String::new();
- match file.read_to_string(&mut s) {
- Err(why) => panic!("Couldn't read {}: {}", display, why),
- Ok(_) => {
- let tasks = parse_file_str(&s);
- let public_html = tasks_to_html(&tasks, CalendarPrivacy::Public);
- let private_html = tasks_to_html(&tasks, CalendarPrivacy::Private);
- // https://riptutorial.com/rust/example/4276/write-in-a-file
- let mut public = File::create(Path::new("public.html")).unwrap();
- writeln!(&mut public, "{}", public_html).unwrap();
- let mut private = File::create(Path::new("private.html")).unwrap();
- writeln!(&mut private, "{}", private_html).unwrap();
- }
+// https://doc.rust-lang.org/std/fs/struct.File.html
+// https://doc.rust-lang.org/book/ch12-01-accepting-command-line-arguments.html
+fn main() {
+ let args: Vec<String> = env::args().collect();
+ let str_args: Vec<&str> = args.iter().map(String::as_str).collect();
+ match str_args[..] {
+ [_, "html"] => command_html(),
+ [_, "describe", week] => command_describe(&week),
+ [_, "generate", week] => command_generate(&week),
+ [_, "validate"] => command_validate(),
+ _ => panic!("Invalid command. Valid commands are: html, describe [week], generate [week], and validate.")
}
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback