From 05d0a83c2ceae1e8e7fa3140e0cc7ae199793f1d Mon Sep 17 00:00:00 2001 From: Robert Attard Date: Wed, 2 Oct 2024 19:05:16 -0400 Subject: [PATCH] prep for v2 as a result of the gleam 1.5 release --- README.md | 30 ++++++++++++++++-------------- gleam.toml | 2 +- src/gladvent.gleam | 8 ++++---- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e4b2ed5..ba686c8 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,15 @@ This library is intended to be imported to your gleam project and used as a comm To add this library to your project run: `gleam add gladvent` and add `import gladvent` to your main gleam file. -## Using the library +> [!IMPORTANT] +> This package works only on gleam's erlang target! + +> [!NOTE] +> Due to changes made in gleam 1.5, users that were calling gladvent via `gleam run -m` should upgrade to v2 and add a call to `gladvent.run` in their project `main` function. -This library provides 2 options to run your advent of code solvers, -once you've added gladvent as a dependency via `gleam add gladvent --dev`: +## Using the library -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. +Once you've added gladvent as a dependency via `gleam add gladvent --dev`, simply add `gladvent.run()` to your project's `main` function. ## Multi-year support @@ -27,10 +29,10 @@ For convenience it defaults to the current year. Therefore, passing `--year=YEAR ## Seeing help messages -- To see available subcommands: `gleam run -m gladvent -- --help` -- To see help for the `run` command: `gleam run -m gladvent run --help` -- To see help for the `run` command: `gleam run -m gladvent run all --help` -- To see help for the `new` command: `gleam run -m gladvent new --help` +- To see available subcommands: `gleam run -- --help` +- To see help for the `run` command: `gleam run run --help` +- To see help for the `run` command: `gleam run run all --help` +- To see help for the `new` command: `gleam run new --help` ## General Workflow @@ -38,10 +40,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 -m gladvent run new X` +1. run `gleam run new X` 2. add your input to `input//day_X.txt` 3. add your code to `src/aoc_/day_X.gleam` -4. run `gleam run -m gladvent run X` +4. run `gleam run run X` ### Available commands @@ -50,7 +52,7 @@ This project provides your application with 2 command groups, `new` and `run`: #### New - `new`: create `src/aoc_/day_.gleam` and `input//.txt` files that correspond to the specified days - - format: `gleam run -m gladvent new a b c ...` + - format: `gleam run new a b c ...` #### Run @@ -58,10 +60,10 @@ The `run` command expects input files to be in the `input/` directory, and (corresponding to the files created by the `new` command). - `run`: run the specified days - - format: `gleam run -m gladvent run a b c ...` + - format: `gleam run run a b c ...` - `run all`: run all registered days - - format: `gleam run -m gladvent run all` + - format: `gleam run run all` _Note:_ diff --git a/gleam.toml b/gleam.toml index 5aa64f7..29b13de 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "gladvent" -version = "1.0.1" +version = "2.0.0" repository = { type = "github", user = "TanklesXL", repo = "gladvent" } description = "An Advent Of Code runner for gleam" licences = ["Apache-2.0"] diff --git a/src/gladvent.gleam b/src/gladvent.gleam index 6c8b83c..a3aa52d 100644 --- a/src/gladvent.gleam +++ b/src/gladvent.gleam @@ -7,10 +7,11 @@ import gleam/string import glint import snag -/// Find all runners in the project src/days/ directory and -/// run either the 'run' or 'new' command as specified +/// Add this function to your project's `main` function in order to run the gladvent CLI. /// -pub fn main() { +/// This function gets its input from the command line arguments by using the `argv` library. +/// +pub fn run() { let commands = glint.new() |> glint.path_help( @@ -18,7 +19,6 @@ pub fn main() { "gladvent is an advent of code runner and generator for gleam. Please use either the 'run' or 'new' commands.", ) |> glint.with_name("gladvent") - |> glint.as_module |> glint.pretty_help(glint.default_pretty_help()) |> glint.group_flag(at: [], of: cmd.year_flag()) |> glint.add(at: ["new"], do: new.new_command())