aoc-star
Library and CLI tool to manage your Advent of Code solutions.
This crate:
- lets you annotate solution functions with a
#[star(day = ..., part = ..., year = ...)]attribute - and provides a small CLI runner that picks the right solution based on command
line flags, loads inputs and (optionally) submits answers via
aoc-client.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Enable the optional features as needed:
[]
= { = "0.1", = ["aoc-client"] }
They allow you to automatically fetch puzzle inputs and submit answers to Advent of Code provided you configure your session cookie (see below).
Usage
Add the dependency to your Cargo.toml, by running:
Annotate your solution functions with the #[star(...)] attribute, specifying
the day, part, and year:
use star;
Build and run:
If you enable the aoc-client feature and configure your session cookie
(see below), you can omit --input-file and the input will be fetched from
Advent of Code directly. You can also use --publish to submit your answer:
Since a single year is used in all functions, you can set it in the config file (see below) and
omit --year:
You can also use a less verbose syntax and use single-dash flags:
See the CLI flags section for more details and run cargo run -- --help
to see all available options.
Example
You can find a complete example project here.
CLI flags
The runner provided by aoc-star::run() accepts:
-d,--day <DAY>: Advent of Code day (1–25). Required.-p,--part <PART>: puzzle part (usually1or2, defaults to1).-y,--year <YEAR>: Advent of Code year. Optional; when omitted, it is resolved from config or the current year.--input-file <PATH>: read the puzzle input fromPATH. If omitted andaoc-clientis enabled, the input will be fetched remotely.--publish: whenaoc-clientis enabled, submit the computed answer to Advent of Code and show the outcome.--setup: If the config file does not exist, create it using the value of theAOC_TOKENenvironment variable as the session cookie and the current year.
Configuration
aoc-star can read a config file to determine:
- your session cookie (needed for remote input fetching and answer submission),
- a default year.
The config is searched in:
- the current directory (
aoc-star.yml), then - the global config directory (typically
~/.config/aoc-star/config.yml).
If none exists, a new config file is created in the global config directory using environment variables and the current year.
Example config
token: "your_aoc_session_cookie_here"
year: 2024
Alternatively, you can set the AOC_TOKEN environment variable; the config
loader will use it when creating a new config.
Features
aoc-client(optional): enable remote input fetching and answer submission with theaoc-clientcrate.test-helpers: export a small testing API:aoc_star::test_helpers::CommandArgumentaoc_star::test_helpers::run_with_result
These are useful for integration tests that want to bypass actual CLI parsing.
Session cookie
To fetch puzzle inputs and submit answers, aoc-star needs your Advent of Code
session cookie.
You can find it by inspecting the cookies in your browser while logged in to
Advent of Code. Look for a cookie named session.
Set it in the config file as shown above, or set the AOC_TOKEN environment
variable before running your binary. You can see more details in the
aoc-cli documentation.
License
This project is licensed under the MIT License and the Apache License (Version 2.0).