aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 2c75a89630a38bf6af11d44bba9f1bbcd574e712 (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
use std::collections::BTreeMap;
use std::env;

fn main() {
    let mut puzzle_solutions: BTreeMap<&str, fn()> = BTreeMap::new();

    puzzle_solutions.insert("y2018::day1::part1", advent_of_code::y2018::day1::part1);
    puzzle_solutions.insert("y2018::day1::part2", advent_of_code::y2018::day1::part2);
    puzzle_solutions.insert("y2018::day2::part1", advent_of_code::y2018::day2::part1);
    puzzle_solutions.insert("y2018::day2::part2", advent_of_code::y2018::day2::part2);
    puzzle_solutions.insert("y2018::day3::part1", advent_of_code::y2018::day3::part1);
    puzzle_solutions.insert("y2018::day3::part2", advent_of_code::y2018::day3::part2);
    puzzle_solutions.insert("y2018::day4::part1", advent_of_code::y2018::day4::part1);
    puzzle_solutions.insert("y2018::day4::part2", advent_of_code::y2018::day4::part2);
    puzzle_solutions.insert("y2018::day5::part1", advent_of_code::y2018::day5::part1);
    puzzle_solutions.insert("y2018::day5::part2", advent_of_code::y2018::day5::part2);
    puzzle_solutions.insert("y2018::day6::part1", advent_of_code::y2018::day6::part1);
    puzzle_solutions.insert("y2018::day6::part2", advent_of_code::y2018::day6::part2);
    puzzle_solutions.insert("y2018::day7::part1", advent_of_code::y2018::day7::part1);
    puzzle_solutions.insert("y2018::day7::part2", advent_of_code::y2018::day7::part2);

    puzzle_solutions.insert("y2019::day1::part1", advent_of_code::y2019::day1::part1);
    puzzle_solutions.insert("y2019::day1::part2", advent_of_code::y2019::day1::part2);

    let command = match env::args().skip(1).next() {
        Some(command) => command,
        None => {
            eprintln!(
                "Usage: advent-of-code <command>\n\nCommands:\n\tlist{}",
                puzzle_solutions
                    .keys()
                    .map(|key| format!("\n\t{}", key))
                    .collect::<String>()
            );
            std::process::exit(1);
        }
    };

    match command.as_str() {
        "list" => {
            for puzzle_solution in puzzle_solutions.keys() {
                println!("{}", puzzle_solution);
            }
            std::process::exit(1);
        }

        puzzle_solution => match puzzle_solutions.get(puzzle_solution) {
            Some(puzzle_solution_fn) => puzzle_solution_fn(),
            None => {
                eprintln!("Puzzle solution '{}' not found", puzzle_solution);
                std::process::exit(1);
            }
        },
    }
}