Skip to main content

cargo_advent/
context.rs

1use crate::{functions, AdventResult};
2use chrono::{Datelike, Utc};
3
4#[derive(Debug)]
5pub struct AppContext {
6    pub app_action: AppAction,
7}
8
9impl AppContext {
10    pub fn run_action(&self) -> AdventResult<()> {
11        self.app_action.run()
12    }
13}
14
15#[derive(Debug)]
16pub enum AppAction {
17    GenerateRustProject {
18        project_name: String,
19        path: String,
20        aoc_data: AocData,
21        template: String,
22    },
23}
24
25impl AppAction {
26    pub fn run(&self) -> AdventResult<()> {
27        match self {
28            AppAction::GenerateRustProject {
29                project_name,
30                path,
31                aoc_data: _,
32                template,
33            } => functions::generate_project::generate_project(
34                project_name.clone(),
35                path.clone(),
36                template.clone(),
37            ),
38        }
39    }
40}
41
42#[derive(Debug, PartialEq)]
43pub struct AocData {
44    /// The base url for the puzzle
45    pub base_url: String,
46    /// The year that the puzzle was published
47    pub year: i32,
48    /// The day that the puzzle was published
49    pub day: u32,
50}
51
52impl Default for AocData {
53    fn default() -> Self {
54        let date = Utc::now();
55        let year = date.year();
56        let day = date.day();
57
58        Self {
59            base_url: "https://adventofcode.com/".to_string(),
60            year,
61            day,
62        }
63    }
64}