feat: download puzzle descriptions (#21)

* add support for downloading puzzle descriptions in `cargo download`
* add `cargo read` command to read puzzles in terminal
* extract `aoc_cli` module
* use `aoc-cli`'s new overwrite option to eliminate temp files
This commit is contained in:
Felix Spöttel
2022-12-06 18:22:40 +01:00
committed by GitHub
parent 7ef01ab32f
commit 4d10812fd3
5 changed files with 193 additions and 78 deletions

View File

@@ -50,7 +50,7 @@ Every [solution](https://github.com/fspoettel/advent-of-code-rust/blob/main/src/
When editing a solution, `rust-analyzer` will display buttons for running / debugging unit tests above the unit test blocks.
### Download input for a day
### Download input & description for a day
> **Note**
> This command requires [installing the aoc-cli crate](#download-puzzle-inputs-via-aoc-cli).
@@ -60,18 +60,20 @@ When editing a solution, `rust-analyzer` will display buttons for running / debu
cargo download <day>
# output:
# Downloading input with aoc-cli...
# Loaded session cookie from "/home/felix/.adventofcode.session".
# Downloading input for day 1, 2021...
# Saving puzzle input to "/tmp/tmp.MBdcAdL9Iw/input"...
# Loaded session cookie from "/Users/<snip>/.adventofcode.session".
# Fetching puzzle for day 1, 2022...
# Saving puzzle description to "src/puzzles/01.md"...
# Downloading input for day 1, 2022...
# Saving puzzle input to "src/inputs/01.txt"...
# Done!
# ---
# 🎄 Successfully wrote input to "src/inputs/01.txt"!
# 🎄 Successfully wrote input to "src/inputs/01.txt".
# 🎄 Successfully wrote puzzle to "src/puzzles/01.md".
```
To download inputs for previous years, append the `--year/-y` flag. _(example: `cargo download 1 --year 2020`)_
Puzzle inputs are not checked into git. [Reasoning](https://old.reddit.com/r/adventofcode/comments/k99rod/sharing_input_data_were_we_requested_not_to/gf2ukkf/?context=3).
Puzzle descriptions are stored in `src/puzzles` as markdown files. Puzzle inputs are not checked into git. [Reasoning](https://old.reddit.com/r/adventofcode/comments/k99rod/sharing_input_data_were_we_requested_not_to/gf2ukkf/?context=3).
### Run solutions for a day
@@ -139,11 +141,28 @@ cargo fmt
cargo clippy
```
### Read puzzle description in terminal
> **Note**
> This command requires [installing the aoc-cli crate](#download-puzzle-inputs-via-aoc-cli).
```sh
# example: `cargo read 1`
cargo read <day>
# output:
# Loaded session cookie from "/Users/<snip>/.adventofcode.session".
# Fetching puzzle for day 1, 2022...
# ...the input...
```
To read inputs for previous years, append the `--year/-y` flag. _(example: `cargo read 1 --year 2020`)_
## Optional template features
### Download puzzle inputs via aoc-cli
1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.5.0`.
1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.7.0`
2. Create an `.adventofcode.session` file in your home directory and paste your session cookie[^1] into it. To get this, press F12 anywhere on the Advent of Code website to open your browser developer tools. Look in your Cookies under the Application or Storage tab, and copy out the `session` cookie value.
Once installed, you can use the [download command](#download-input-for-a-day).