A small CLI for fetching Advent of Code puzzles and inputs, and submitting answers.
brew install ahacop/tap/aoc-cliFor one-off use:
nix run github:ahacop/aoc-cli -- puzzle 2023 1To pull it into a NixOS / home-manager config that's itself a flake, add it as an input:
# flake.nix
inputs.aoc-cli = {
url = "github:ahacop/aoc-cli";
inputs.nixpkgs.follows = "nixpkgs";
};…and reference the package wherever you list packages:
environment.systemPackages = [
inputs.aoc-cli.packages.${pkgs.stdenv.hostPlatform.system}.default
];
# or, in home-manager:
home.packages = [
inputs.aoc-cli.packages.${pkgs.stdenv.hostPlatform.system}.default
];cargo install --git https://github.com/ahacop/aoc-cliPre-built binaries for aarch64-apple-darwin, aarch64-unknown-linux-gnu, and x86_64-unknown-linux-gnu are attached to each GitHub Release, along with a curl | sh installer.
aoc login # acquire and store an AoC session cookie
aoc where # print where the session file lives
aoc puzzle 2023 1 # render the puzzle text for day 1 of 2023
aoc input 2023 1 # download the puzzle input (cached on disk thereafter)
aoc input 2023 1 --refresh # bypass and overwrite the local cache
aoc submit 2023 1 1 12345 # submit `12345` as the answer to part 1
my-solver | aoc submit 2023 1 1 # or pipe the answer from stdin
aoc next 2023 # print "<day> <part>" for the lowest day not yet 2-starred
aoc stars 2023 # show stars earned per day, plus the total
aoc open 2023 1 # open the puzzle page in your browseraoc login with no argument first tries to read the session cookie out of local browsers (Firefox, LibreWolf, Zen, plus whatever rookie supports). If that fails it opens the AoC login page so you can paste a token from document.cookie.
Inputs are cached under your platform cache dir (~/.cache/aoc-cli/inputs/<year>/<day>.txt on Linux). Per AoC's automation guidelines they're stable per user, so the file is kept indefinitely — pass --refresh, or just delete it, to re-fetch.
Status messages go to stderr; puzzle text and input go to stdout, so:
aoc input 2023 1 > input.txtThe dev shell (entered automatically via direnv / flake.nix) provides the Rust toolchain plus cargo-watch, cargo-edit, just, and cargo-dist. If a tool is missing on a NixOS host, wrap it in nix-shell -p <pkg> --run "...".
cargo build # debug build
cargo build --release # release build
cargo run -- puzzle 2023 1 # run subcommand
cargo test # tests
cargo clippy --all-targets -- -D warnings
cargo fmt
nix build # produces ./result/bin/aocReleases are automated by cargo-dist (invoked as dist). A tag push to GitHub triggers .github/workflows/release.yml, which:
- Builds binaries for all three target triples in parallel.
- Creates a GitHub Release and uploads tarballs + checksums + a shell installer.
- Generates a Homebrew formula and pushes it to
ahacop/homebrew-tap.
A GitHub PAT with contents: write on ahacop/homebrew-tap must be available to this repo as a secret named HOMEBREW_TAP_TOKEN:
gh secret set HOMEBREW_TAP_TOKEN --repo ahacop/aoc-clicargo set-version 0.2.0 # whatever bump
git commit -am "Release v0.2.0"
git tag v0.2.0
git push && git push --tagsThe tag push fires the workflow; binaries and the updated Homebrew formula land within a few minutes.
The workflow pins itself to the dist version that generated it (currently 0.30.4, from nixpkgs). When the flake bumps cargo-dist, regenerate so CI matches:
dist init --yesThen commit dist-workspace.toml and .github/workflows/release.yml.