From da639ade238e9fd57805990fc56d32615564fabd Mon Sep 17 00:00:00 2001 From: sloane Date: Thu, 21 Nov 2024 21:51:25 -0500 Subject: [PATCH] parse command line arguments, get default date --- 2024/gleam.toml | 3 +++ 2024/manifest.toml | 11 +++++++++++ 2024/src/aoc.gleam | 44 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/2024/gleam.toml b/2024/gleam.toml index e299b57..896dae6 100644 --- a/2024/gleam.toml +++ b/2024/gleam.toml @@ -14,6 +14,9 @@ version = "1.0.0" [dependencies] gleam_stdlib = ">= 0.34.0 and < 2.0.0" +glint = ">= 1.1.0 and < 2.0.0" +argv = ">= 1.0.2 and < 2.0.0" +birl = ">= 1.7.1 and < 2.0.0" [dev-dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" diff --git a/2024/manifest.toml b/2024/manifest.toml index 4721e5c..977a4d1 100644 --- a/2024/manifest.toml +++ b/2024/manifest.toml @@ -2,10 +2,21 @@ # You typically do not need to edit this file packages = [ + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "birl", version = "1.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "5C66647D62BCB11FE327E7A6024907C4A17954EF22865FE0940B54A852446D01" }, + { name = "gleam_community_ansi", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "4CD513FC62523053E62ED7BAC2F36136EC17D6A8942728250A9A00A15E340E4B" }, + { name = "gleam_community_colour", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "386CB9B01B33371538672EEA8A6375A0A0ADEF41F17C86DDCB81C92AD00DA610" }, + { name = "gleam_json", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "0A57FB5666E695FD2BEE74C0428A98B0FC11A395D2C7B4CDF5E22C5DD32C74C6" }, { name = "gleam_stdlib", version = "0.43.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "69EF22E78FDCA9097CBE7DF91C05B2A8B5436826D9F66680D879182C0860A747" }, { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, + { name = "glint", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "A3F1B7C665FD216BE6A886D56537F0E095FB07DF62146074109270B798F8CEC4" }, + { name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" }, + { name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" }, ] [requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +birl = { version = ">= 1.7.1 and < 2.0.0" } gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } +glint = { version = ">= 1.1.0 and < 2.0.0" } diff --git a/2024/src/aoc.gleam b/2024/src/aoc.gleam index 26987ac..bfd7936 100644 --- a/2024/src/aoc.gleam +++ b/2024/src/aoc.gleam @@ -1,5 +1,47 @@ +import argv +import birl +import gleam/int import gleam/io +import gleam/list +import gleam/string +import glint + +fn day_flag() -> glint.Flag(Int) { + let flag = + glint.int_flag("day") + |> glint.flag_help("The day to run") + + case birl.now() |> birl.get_day() { + birl.Day(year: _, month: 12, date: date) -> + flag + |> glint.flag_default(date) + _ -> flag + } +} + +fn parts_flag() -> glint.Flag(List(Int)) { + glint.ints_flag("part") + |> glint.flag_default([1, 2]) + |> glint.flag_help("The part(s) to run") +} + +fn run() -> glint.Command(Nil) { + use day <- glint.flag(day_flag()) + use parts <- glint.flag(parts_flag()) + use _, _, flags <- glint.command() + let assert Ok(day) = day(flags) + let assert Ok(parts) = parts(flags) + io.println(int.to_string(day)) + parts + |> list.map(int.to_string) + |> string.join(", ") + |> io.println() +} pub fn main() { - io.println("Hello from aoc!") + glint.new() + |> glint.with_name("run") + |> glint.pretty_help(glint.default_pretty_help()) + |> glint.add(at: [], do: run()) + |> glint.run(argv.load().arguments) }