Skip to content

Commit

Permalink
update to gleam 0.32.4
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Nov 13, 2023
1 parent 2b8224f commit 6d0a32f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gleam 0.30.5
gleam 0.32.4
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ To add this library to your project run: `gleam add gladvent` and add `import gl

## Using the library

This library provides 2 options to run your advent of code solvers:
This library provides 3 options to run your advent of code solvers:

1. The easiest way: call it via `gleam run -m gladvent [ARGS]`, not requiring a custom `main()` function.
1. The easy way: simply add `gladvent.main()` to the end of your project's `main` function.
2. Create your own `Map(Int, #(fn(String) -> Dynamic, fn(String) -> Dynamic))` and pass it to `gladvent.execute`

## Multi-year support

Gladvent now comes with out-of-the-box multi-year support via the ` --year`` flag when running it. For convenience it defaults to the current year. Therefore, passing the `--year=<YEAR>`flag to either the`run`, `run all`or`new` commands will use the year specified or the current year if the flag was not provided.

## Available commands

Expand Down Expand Up @@ -44,10 +48,8 @@ This project provides your application with 2 commands, `new` and `run`:

_Note:_

- due to how `gladvent` works, the `pt_1` and `pt_2` functions only need to return `Dynamic` when directly building a `RunnerMap` and using `gladvent.execute`, when using `gladvent.main` they can return anything.
- the `new` command creates source files in `src/days/` and input files in the `input/` directory.
- the `run` command expects input files to be in the `input/` directory.
- using `gladvent.main` expects gleam day runners to be in `src/days/`
- the `new` command creates source files in `src/aoc_<YEAR>/` and input files in the `input/<YEAR>` directory.
- the `run` command expects input files to be in the `input/<YEAR>` directory, and code to be in `src/aoc_<YEAR>/`
- any triggered `assert` will be captured and printed, for example: `error: assert - Assertion pattern match failed in module days/day_1 in function pt_1 at line 2 with value 2`
- any message in a `todo` will be captured and printed, for example: `error: todo - test in module days/day_1 in function pt_2 at line 7`

Expand All @@ -64,10 +66,10 @@ Where X is the day you'd like to add (when using `gladvent.main()`):

_Note:_ this method requires all day solutions be in `src/days/` with filenames `day_X.gleam`, each solution module containing `fn pt_1(String) -> Int` and a `fn pt_2(String) -> Int`

1. run `gleam run new X`
2. add your input to `input/day_X.txt`
3. add your code to `src/days/day_X.gleam`
4. run `gleam run run X`
1. run `gleam run -m gladvent run new X`
2. add your input to `input/<YEAR>/day_X.txt`
3. add your code to `src/aoc_<YEAR>/day_X.gleam`
4. run `gleam run -m gladvent run X`

## FAQ

Expand Down
6 changes: 4 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "gladvent"
version = "0.5.1"
version = "0.6.0"
repository = { type = "github", user = "TanklesXL", repo = "gladvent" }
description = "An Advent Of Code runner for gleam"
licences = ["Apache-2.0"]
internal_modules = ["gladvent/internal/*", "aoc_*"]
gleam = ">= 0.32.0"

[dependencies]
gleam_stdlib = "~> 0.19"
gleam_otp = "~> 0.4"
gleam_erlang = "~> 0.7"
snag = "~> 0.2"
glint = "0.12.0-rc6"
glint = " ~> 0.12"
simplifile = "~> 0.3"

[dev-dependencies]
gleeunit = "~> 0.6"
17 changes: 9 additions & 8 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_bitwise", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "E2A46EE42E5E9110DAD67E0F71E7358CBE54D5EC22C526DD48CBBA3223025792" },
{ name = "gleam_community_ansi", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_bitwise", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "6E4E0CF2B207C1A7FCD3C21AA43514D67BC7004F21F82045CDCCE6C727A14862" },
{ name = "gleam_community_colour", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_bitwise"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "D27CE357ECB343929A8CEC3FBA0B499943A47F0EE1F589EE16AFC2DC21C61E5B" },
{ name = "gleam_erlang", version = "0.21.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A502A9DE61CEBC94B9D55A1FD41D0EA735A82D74E926E3D874CBA69F3705BDB2" },
{ name = "gleam_otp", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "E31B158857E3D2AF946FE6E90E0CB21699AF226F4630E93FBEAC5DB4515F8920" },
{ name = "gleam_stdlib", version = "0.30.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "704258528887F95075FFED7AAE1CCF836A9B88E3AADA2F69F9DA15815F94A4F9" },
{ name = "gleam_community_ansi", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8B5A9677BC5A2738712BBAF2BA289B1D8195FDF962BBC769569976AD5E9794E1" },
{ name = "gleam_community_colour", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "036C206886AFB9F153C552700A7A0B4D2864E3BC96A20C77E5F34A013C051BE3" },
{ name = "gleam_erlang", version = "0.23.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DA7A8E5540948DE10EB01B530869F8FF2FF6CAD8CFDA87626CE6EF63EBBF87CB" },
{ name = "gleam_otp", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "18EF8242A5E54BA92F717C7222F03B3228AEE00D1F286D4C56C3E8C18AA2588E" },
{ name = "gleam_stdlib", version = "0.32.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "ABF00CDCCB66FABBCE351A50060964C4ACE798F95A0D78622C8A7DC838792577" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "glint", version = "0.12.0-rc6", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_community_ansi", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "569EF5A6DA6F7EF310C57693240969BBBA20E78447D32598EA7BA3542243160F" },
{ name = "glint", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "799D6C76990EE1265396D7BEB5771AE902C3221AD79BA0B70A4FBADAEBAC1A1A" },
{ name = "simplifile", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "45E2C6C7FD8D931A660CA56880EC75186BB39C84F36951B4EE284F6F95E8F65D" },
{ name = "snag", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "8FD70D8FB3728E08AC425283BB509BB0F012BE1AE218424A597CDE001B0EE589" },
]

Expand All @@ -18,5 +18,6 @@ gleam_erlang = { version = "~> 0.7" }
gleam_otp = { version = "~> 0.4" }
gleam_stdlib = { version = "~> 0.19" }
gleeunit = { version = "~> 0.6" }
glint = { version = "0.12.0-rc6" }
glint = { version = " ~> 0.12" }
simplifile = { version = "~> 0.3" }
snag = { version = "~> 0.2" }
4 changes: 2 additions & 2 deletions src/gladvent/internal/cmd.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gleam/result
import gladvent/internal/parse.{Day}
import gleam/otp/task.{Task}
import gladvent/internal/parse.{type Day}
import gleam/otp/task.{type Task}
import gleam/erlang
import gleam/pair
import gleam/list
Expand Down
10 changes: 5 additions & 5 deletions src/gladvent/internal/cmd/new.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import gleam/result
import gleam/list
import gleam/string
import gladvent/internal/file
import gleam/erlang/file as efile
import simplifile as efile
import gladvent/internal/cmd
import glint
import glint/flag
import gladvent/internal/parse.{Day}
import gladvent/internal/parse.{type Day}
import gleam/pair

type Context {
Expand Down Expand Up @@ -72,12 +72,12 @@ fn gleam_src_path(year: Int, day: Day) -> String {
}

fn create_dir(dir: String) -> Result(String, Err) {
efile.make_directory(dir)
efile.create_directory(dir)
|> handle_dir_open_res(dir)
}

fn handle_dir_open_res(
res: Result(_, efile.Reason),
res: Result(_, efile.FileError),
filename: String,
) -> Result(String, Err) {
case res {
Expand All @@ -90,7 +90,7 @@ fn handle_dir_open_res(
}
}

fn handle_file_open_failure(reason: efile.Reason, filename: String) -> Err {
fn handle_file_open_failure(reason: efile.FileError, filename: String) -> Err {
case reason {
efile.Eexist -> FileAlreadyExists(filename)
_ -> FailedToCreateFile(filename)
Expand Down
16 changes: 8 additions & 8 deletions src/gladvent/internal/cmd/run.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import gleam/int
import gleam/list
import gleam/result
import gleam/string
import snag.{Result, Snag}
import gleam/erlang/file
import snag.{type Result, type Snag}
import simplifile
import gleam/erlang
import gleam/erlang/charlist.{Charlist}
import gleam/erlang/charlist.{type Charlist}
import gleam/erlang/atom
import gladvent/internal/parse.{Day}
import gladvent/internal/parse.{type Day}
import gleam/map
import gladvent/internal/cmd.{Ending, Endless}
import glint
import glint/flag
import gleam
import gladvent/internal/runners.{RunnerMap}
import gleam/dynamic.{Dynamic}
import gleam/option.{None, Option}
import gladvent/internal/runners.{type RunnerMap}
import gleam/dynamic.{type Dynamic}
import gleam/option.{type Option, None}
import gleam/pair

type SolveErr {
Expand Down Expand Up @@ -72,7 +72,7 @@ fn do(

use input <- result.then(
input_path
|> file.read()
|> simplifile.read()
|> result.map(string_trim(_, Both, "\n"))
|> result.replace_error(FailedToReadInput(input_path)),
)
Expand Down
15 changes: 9 additions & 6 deletions src/gladvent/internal/file.gleam
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import gleam/erlang/file.{Reason}
import simplifile.{type FileError}
import gleam/result

pub type IODevice

@external(erlang, "gladvent_ffi", "open_file_exclusive")
pub fn open_file_exclusive(s s: String) -> Result(IODevice, Reason)
pub fn open_file_exclusive(s s: String) -> Result(IODevice, FileError)

@external(erlang, "gladvent_ffi", "write")
fn do_write(a: IODevice, b: String) -> Result(Nil, Reason)
fn do_write(a: IODevice, b: String) -> Result(Nil, FileError)

pub fn write(iod: IODevice, s: String) -> Result(Nil, Reason) {
pub fn write(iod: IODevice, s: String) -> Result(Nil, FileError) {
do_write(iod, s)
}

@external(erlang, "gladvent_ffi", "close_iodevice")
fn close_iodevice(a: IODevice) -> Result(Nil, Reason)
fn close_iodevice(a: IODevice) -> Result(Nil, FileError)

pub fn do_with_file(filename: String, f: fn(IODevice) -> a) -> Result(a, Reason) {
pub fn do_with_file(
filename: String,
f: fn(IODevice) -> a,
) -> Result(a, FileError) {
use file <- result.map(open_file_exclusive(filename))
use <- defer(do: fn() {
let assert Ok(Nil) = close_iodevice(file)
Expand Down
2 changes: 1 addition & 1 deletion src/gladvent/internal/parse.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import snag.{Result}
import snag.{type Result}
import gleam/int
import gleam/list
import gleam/result
Expand Down
10 changes: 5 additions & 5 deletions src/gladvent/internal/runners.gleam
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import gleam/map.{Map}
import gleam/erlang/atom.{Atom}
import gleam/map.{type Map}
import gleam/erlang/atom.{type Atom}
import gleam/string
import snag.{Result}
import gladvent/internal/parse.{Day}
import snag.{type Result}
import gladvent/internal/parse.{type Day}
import gleam/list
import gleam/result
import gleam
import gleam/dynamic.{Dynamic}
import gleam/dynamic.{type Dynamic}
import gleam/int

pub type PartRunner =
Expand Down

0 comments on commit 6d0a32f

Please sign in to comment.