summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 49c81523cf63a4bd18699786d19dd3e22e78f8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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::*;

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
}

fn command_validate() {
    // TODO
}

// 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