|
3 | 3 | [](https://pkg.go.dev/github.com/dolfolife/aoctl#section-readme) |
4 | 4 | [](https://codecov.io/github/dolfolife/aoctl) |
5 | 5 |
|
6 | | -This is a personal project for myself to learn more about writing CLI tools in GoLang. The idea behind this project is to help me solve the [Advent of Code](adventofcode.com/) since I have noticed some patterns while solving them. |
| 6 | +A simple CLI tool to organize and solve [Advent of Code](https://adventofcode.com/) problems. It handles downloading inputs, generating boilerplate code, and running your solutions, so you can focus on the logic. |
7 | 7 |
|
8 | | -> Disclaimer: This is yet another CLI that solves a common problem and there are probably `n` solutions out there. My motivation is not only to provide a CLI but to learn how to write, develop, release, and test them. |
| 8 | +## Features |
9 | 9 |
|
10 | | -I hope you enjoy it and feel free to help me understand the best practices of writing CLI tools or GoLang packages by writing an issue or using the [CONTRIBUTING.md](./CONTRIBUTING.md) to contribute. PRs are welcome. |
| 10 | +- **Project Initialization**: Sets up a clean workspace for your AoC solutions. |
| 11 | +- **Synchronization**: Downloads puzzle descriptions (README.md) and inputs for all available days. |
| 12 | +- **Code Generation**: Generates simple Go boilerplate for each day. |
| 13 | +- **Zero Friction**: No complex interfaces to implement. Just write `Part1` and `Part2` functions. |
11 | 14 |
|
12 | | -## Advent Of Code Series |
| 15 | +## Installation |
13 | 16 |
|
14 | | -Advent of Code is a website made by Eric Wastl. I recommend watching [Advent of Code: Behind the Scenes](https://www.youtube.com/watch?v=CFWuwNDOnIo&ab_channel=CodingTech). |
15 | | - |
16 | | -## The Why |
17 | | - |
18 | | -Advent of Code application only cares about your solution, but there is no way to link your code and the problem at hand. The main idea of this tool is to give you a link between the application of [adventofcode.com](https://adventofcode.com/) and your working space. |
19 | | - |
20 | | -## Alternatives |
21 | | - |
22 | | -I found [Advent Of Code Go](https://github.com/alexchao26/advent-of-code-go) and it inspired me to build my own tool and learn more GoLang. |
23 | | - |
24 | | -# AoC CLI Documentation |
25 | | - |
26 | | -## Pre-requisite |
27 | | - |
28 | | -You need your session ID from the Advent of Code website. I opened an issue for this: [Session ID is a manual process issue](https://github.com/dolfolife/aoctl/issues/1). |
29 | | - |
30 | | -## Puzzles |
31 | | - |
32 | | -The Advent of Code puzzles have two parts. Each part has a single string input and a single output. |
| 17 | +```bash |
| 18 | +go install github.com/dolfolife/aoctl@latest |
| 19 | +``` |
33 | 20 |
|
34 | | -By that, we have to create an interface that allows us to run each solution against the input and submit the solution to the server of Advent of Code. |
| 21 | +## Usage |
35 | 22 |
|
36 | | -## Commands |
| 23 | +### 1. Initialize Project |
37 | 24 |
|
38 | | -### Init |
39 | | -Initialize the aoc project in your local machine. |
| 25 | +Start by creating a new directory for your Advent of Code solutions and initializing it: |
40 | 26 |
|
41 | 27 | ```bash |
42 | | -aoc init <path> |
| 28 | +mkdir my-aoc-solutions |
| 29 | +cd my-aoc-solutions |
| 30 | +aoctl init . |
43 | 31 | ``` |
44 | 32 |
|
45 | | -### Version |
46 | | -Print current version of the cli |
| 33 | +### 2. Configure Session |
| 34 | + |
| 35 | +To download inputs, you need to provide your Advent of Code session cookie. You can find this in your browser's developer tools (Application -> Cookies) when logged into adventofcode.com. |
47 | 36 |
|
48 | 37 | ```bash |
49 | | -aoc version |
| 38 | +aoctl session --session <your-session-cookie> |
50 | 39 | ``` |
51 | 40 |
|
52 | | -#### Options |
53 | | - |
54 | | -``` |
55 | | ---path -p Path to initialize the project |
56 | | -``` |
| 41 | +### 3. Synchronize Puzzles |
57 | 42 |
|
58 | | -### Puzzle |
59 | | -Get The puzzle information with the option to save it locally in the repository. |
| 43 | +Download the puzzles and generate the boilerplate code for the current year (or previous years). |
60 | 44 |
|
61 | 45 | ```bash |
62 | | -aoc puzzles [OPTIONS] |
| 46 | +aoctl synchronize |
63 | 47 | ``` |
64 | 48 |
|
65 | | -#### Options |
| 49 | +This will create a directory structure like this: |
66 | 50 |
|
67 | 51 | ``` |
68 | | --s --session (required) Advent of Code Session. You can get this in the Cookies of the website. |
| 52 | +events/ |
| 53 | + 2024/ |
| 54 | + 01/ |
| 55 | + README.md # The puzzle description |
| 56 | + input/ |
| 57 | + input.txt # The puzzle input |
| 58 | + main.go # Entry point to run your solution |
| 59 | + solution.go # Where you write your code |
| 60 | + solution_test.go # Tests for your solution |
69 | 61 | ``` |
70 | 62 |
|
71 | | -``` |
72 | | --d --day (required) Day of the puzzle you want to get. |
73 | | -``` |
| 63 | +### 4. Solve the Puzzle |
74 | 64 |
|
75 | | -``` |
76 | | --y --year (required) Year of the puzzle you want to get. |
77 | | -``` |
| 65 | +Open `events/2024/01/solution.go` and implement `Part1` and `Part2`. |
78 | 66 |
|
79 | | -``` |
80 | | ---sync (optional) To save the puzzle locally at `<year>/<day>/puzzle.md |
| 67 | +```go |
| 68 | +package main |
| 69 | + |
| 70 | +func Part1(input string) (string, error) { |
| 71 | + // Your logic here |
| 72 | + return "answer", nil |
| 73 | +} |
| 74 | + |
| 75 | +func Part2(input string) (string, error) { |
| 76 | + // Your logic here |
| 77 | + return "answer", nil |
| 78 | +} |
81 | 79 | ``` |
82 | 80 |
|
83 | | -### test |
84 | | -Locally test your answers. This relies that each `<year>/<day>` solution has its own tests. |
| 81 | +### 5. Run and Test |
85 | 82 |
|
86 | | -> not yet implemented |
| 83 | +Run your solution: |
87 | 84 |
|
88 | 85 | ```bash |
89 | | -aoc test [OPTIONS] |
| 86 | +cd events/2024/01 |
| 87 | +go run . |
90 | 88 | ``` |
91 | 89 |
|
92 | | -### submit |
93 | | -Submit your answer to the Advent of Code. |
94 | | - |
95 | | -> not yet implemented |
| 90 | +Run tests: |
96 | 91 |
|
97 | 92 | ```bash |
98 | | -aoc submit [OPTIONS] |
| 93 | +go test . |
99 | 94 | ``` |
100 | 95 |
|
101 | | -#### Options |
| 96 | +## Helper Functions |
102 | 97 |
|
103 | | -``` |
104 | | --s --session (required) Advent of Code Session. You can get this in the Cookies of the website. |
105 | | -``` |
| 98 | +The `pkg/puzzle` package provides a simple helper to read the input file: |
106 | 99 |
|
107 | | -``` |
108 | | --d --day (required) Day of the puzzle you want to get. |
109 | | -``` |
| 100 | +```go |
| 101 | +import "github.com/dolfolife/aoctl/pkg/puzzle" |
110 | 102 |
|
| 103 | +input, err := puzzle.ReadInput("input/input.txt") |
111 | 104 | ``` |
112 | | --y --year (required) Year of the puzzle you want to get. |
113 | | -``` |
| 105 | + |
| 106 | +## Contributing |
| 107 | + |
| 108 | +PRs are welcome! Please check [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines. |
0 commit comments