Skip to content

Commit

Permalink
prep for v2 as a result of the gleam 1.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Oct 2, 2024
1 parent 23aff69 commit 05d0a83
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,21 +29,21 @@ 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

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/<YEAR>/day_X.txt`
3. add your code to `src/aoc_<YEAR>/day_X.gleam`
4. run `gleam run -m gladvent run X`
4. run `gleam run run X`

### Available commands

Expand All @@ -50,18 +52,18 @@ This project provides your application with 2 command groups, `new` and `run`:
#### New

- `new`: create `src/aoc_<year>/day_<day>.gleam` and `input/<year>/<day>.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

The `run` command expects input files to be in the `input/<year>` directory, and code to be in `src/aoc_<year>/`
(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:_

Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions src/gladvent.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ 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(
[],
"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())
Expand Down

0 comments on commit 05d0a83

Please sign in to comment.