17 个版本 (11 个重大更改)
| 0.12.0 | 2023年1月12日 | 
|---|---|
| 0.10.0 | 2022年12月21日 | 
| 0.5.0 | 2022年11月25日 | 
| 0.3.0 | 2021年12月1日 | 
| 0.2.0 | 2020年12月11日 | 
#905 in 命令行工具
66 每月下载量
57KB
938 行
aoc-cli
Advent of Code 命令行工具 🎄
aoc-cli 是一个用于 Advent of Code 的命令行工具。它允许您从终端舒适地读取谜题描述、下载谜题输入、提交答案并检查答案是否正确。它使用 aoc-client 库构建。
特性 ⭐️
- 从文件或环境变量中加载 Advent of Code 会话 cookie。
- 读取谜题描述,可选地将其保存为 Markdown 格式的文件。
- 下载谜题输入。
- 提交您的谜题答案并检查答案是否正确。
- 检查您在 Advent of Code 日历中的进度(收集的星星)。
- 显示私有排行榜的状态。
- 验证参数(年份、天数、谜题部分)并检查谜题是否已解锁。
- 如果没有提供年份,默认为当前或上一次 Advent of Code 活动。
- 当可能时推断谜题天数(当前和过去事件的最后一个已解锁谜题)。
安装选项 🎅
从源码编译
- 使用 rustup 安装 Rust 的最新版本或使用以下命令更新它:
# rustup update
aoc-cli 依赖于 openssl-sys,它需要 OpenSSL 库和头文件进行编译。在 Linux 上,您需要安装包含 OpenSSL 开发头文件的软件包,例如 libssl-dev 或 openssl-devel。
- 使用 cargo 安装 aoc-cli
# cargo install aoc-cli
Homebrew
在 macOS 和 Linux 上,使用 Homebrew
# brew install scarvalhojr/tap/aoc-cli
Windows 包管理器
在 Windows 10 和 11 上,使用 Windows 包管理器 命令行工具
# winget install aoc-cli
下载发布工件
所选平台的可执行文件可在GitHub 发布版中获取。只需下载并解压文件。Windows 系统还提供了安装程序。
Linux 包使用静态链接的 OpenSSL 和 musl C 库,应在大多数 Linux 发行版上正常工作。
macOS 和 Windows 包应自动检测已安装的 OpenSSL 库。MSVC Windows 包需要 redistributable Visual C++ 运行时库,而 MinGW 包需要 Minimalist GNU for Windows 运行时库。
- x86 64 位 Linux - aoc-cli-<版本>-x86_64-unknown-linux-musl.tar.gz
- x86 64 位 macOS (10.7 或更高版本) - aoc-cli-<版本>-x86_64-apple-darwin.tar.gz
- x86 64 位 Windows 安装程序 - aoc-cli-<版本>-x86_64.msi
- x86 64 位 Windows MSVC (Windows 7 或更高版本) - aoc-cli-<版本>-x86_64-pc-windows-msvc.zip
- x86 64 位 Windows MinGW (Windows 7 或更高版本) - aoc-cli-<版本>-x86_64-pc-windows-gnu.zip
- i686 32 位 Windows MSVC (Windows 7 或更高版本) - aoc-cli-<版本>-i686-pc-windows-msvc.zip
- i686 32 位 Windows MinGW (Windows 7 或更高版本) - aoc-cli-<版本>-i686-pc-windows-gnu.zip
会话 cookie 🍪
不同的 Advent of Code 用户会得到不同的谜题输入。要下载您的输入并提交答案,您需要一个 adventofcode.com 的会话 cookie。要获取您的会话 cookie,请登录到 Advent of Code 网站,并检查存储在浏览器中的 cookie 的 session 值 - 请参阅此处的说明。
会话 cookie(一个长的十六进制字符串)必须以单行形式(不换行)提供,以下方式之一(按优先级列出):
- 通过 --session-file命令行选项指定的文件中。
- 在 ADVENT_OF_CODE_SESSION环境变量中。
- 在您的家目录中名为 .adventofcode.session(注意点)的文件中(Linux 上的/home/alice,Windows 上的C:\Users\Alice,macOS 上的/Users/Alice)。
- 在用户配置目录下的名为 adventofcode.session(没有点)的文件中(Linux上的/home/alice/.config,Windows上的C:\Users\Alice\AppData\Roaming,macOS上的/Users/Alice/Library/Application Support)。
使用方法 ⛄️
# aoc help
Advent of Code command-line tool
Usage: aoc [OPTIONS] [COMMAND]
Commands:
  calendar             Show Advent of Code calendar and stars collected [aliases: c]
  download             Save puzzle description and input to files [aliases: d]
  read                 Read puzzle statement (the default command) [aliases: r]
  submit               Submit puzzle answer [aliases: s]
  private-leaderboard  Show the state of a private leaderboard [aliases: p]
  help                 Print this message or the help of the given subcommand(s)
Options:
  -d, --day <DAY>            Puzzle day [default: last unlocked day (during Advent of Code month)]
  -y, --year <YEAR>          Puzzle year [default: year of current or last Advent of Code event]
  -s, --session-file <PATH>  Path to session cookie file [default: ~/.adventofcode.session]
  -w, --width <WIDTH>        Width at which to wrap output [default: terminal width]
  -o, --overwrite            Overwrite files if they already exist
  -I, --input-only           Download puzzle input only
  -P, --puzzle-only          Download puzzle description only
  -i, --input-file <PATH>    Path where to save puzzle input [default: input]
  -p, --puzzle-file <PATH>   Path where to save puzzle description [default: puzzle.md]
  -q, --quiet                Restrict log messages to errors only
      --debug                Enable debug logging
  -h, --help                 Print help information
  -V, --version              Print version information
# aoc help submit
Submit puzzle answer
Usage: aoc submit [OPTIONS] <PART> <ANSWER>
Arguments:
  <PART>    Puzzle part [possible values: 1, 2]
  <ANSWER>  Puzzle answer
Options:
  -d, --day <DAY>            Puzzle day [default: last unlocked day (during Advent of Code month)]
  -y, --year <YEAR>          Puzzle year [default: year of current or last Advent of Code event]
  -s, --session-file <PATH>  Path to session cookie file [default: ~/.adventofcode.session]
  -w, --width <WIDTH>        Width at which to wrap output [default: terminal width]
  -o, --overwrite            Overwrite files if they already exist
  -I, --input-only           Download puzzle input only
  -P, --puzzle-only          Download puzzle description only
  -i, --input-file <PATH>    Path where to save puzzle input [default: input]
  -p, --puzzle-file <PATH>   Path where to save puzzle description [default: puzzle.md]
  -q, --quiet                Restrict log messages to errors only
      --debug                Enable debug logging
  -h, --help                 Print help information
阅读谜题描述
在终端中,以纯文本格式阅读今天的谜题(如果今天是 Advent of Code 的一天)。
# aoc read
[INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool
## --- Day 2: Rock Paper Scissors ---
The Elves begin to set up camp on the beach. To decide whose tent gets to be
closest to the snack storage, a giant [Rock Paper Scissors][1] tournament is
already in progress.
...
下载谜题输入
下载今天的谜题描述和输入,并将它们保存到文件中。默认情况下,描述保存在“puzzle.md”文件中,输入保存在当前目录的“input”文件中
# aoc download
[INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool
[INFO  aoc::aoc] 🎅 Saved puzzle description to 'puzzle.md'
[INFO  aoc::aoc] 🎅 Saved puzzle input to 'input'
提交谜题答案
提交今天谜题的第一部分的答案(例如,答案是 999)
# aoc submit 1 999
[INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool
That's the right answer! You are one gold star closer to saving your vacation. [[Continue to Part Two]][1]
[1] /2022/day/2#part2
查看您的 Advent of Code 日历
检查您的进度,查看您自己的日历。您甚至可以查看过去的事件
# aoc calendar --year 2015
[INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool
                        *                          25
                       >o<                         24
                      >o<<<                        23
                     >>O<<o<                       22
                    >>o>O>>@<                      21
                   >O<o>>@>>*<                     20
                  >o>*<<<O<o>O<                    19
                 >>o<@<<<o>>>o<<                   18
                >>*>o>>>*>>>O<<<<                  17
               >*<@>>>*>>O>o<o>@<<                 16
              >O>>>O<<@<<o>>>@>>>O<                15
             >>O>>*>>@<<o<<<@>>>*>O<               14
            >O<<<@>>o>O>o<<@>>O>>o>*<              13
           >>@>>O>>*<O<o<<O<*<<<*<*<<<             12
          >>*>>>*<<<O<<@>>O>>>o<<<o<<*<            11
         >*>>>*<<@>>@<<<@<<o<o<<<@<<<*<<           10
        >>o>>>*<<@<<@<<<O>O<<<@>>>O>O<<<<           9
       >>o>*<<o>>o<<<*<<@>>o<<<@>@<<<@<<<<          8
      >@>>>@<o<<<@>>*<O<<<o<<O>>>o>*<<O<o<<         7
     >o>>*>*<<@>*<<<o>*>>>@<O<<*>>>@<<*<o>o<        6
    >>o<<*<<<*>*<<<*<<*<o<<*>>>*>>>o>>O>*<<<<       5 **
   >O>>>o<<<o>O<<<O>*>o<O>>o>>O<o>O>@<@>>o<<<<      4 **
  >@>O<<<o>>*>>*<<O>o<*<<o<<o>>>@>>>*<<@>o<<<o<     3 **
 >>@<<<@<<<@<<<O<<*>o>O<<<O>>o<@>o<<<*>*>>>O>>O<    2 **
>O>>>O>*>>>@<*>>>@>@<<*<@<<o>>>o>>>@>>o>@>>*>>O<<   1 **
                      |   |
                      |   |
           _  _ __ ___|___|___ __ _  _
显示私人排行榜
如果您是私人排行榜的成员,可以通过传递排行榜号码来查看您与朋友的表现
# aoc private-leaderboard 1234
[INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool
Private leaderboard of me & my friends for Advent of Code 2022.
Gold * indicates the user got both stars for that day,
silver * means just the first star, and a gray dot (.) means none.
                 1111111111222222
        1234567890123456789012345
 1) 274 **********.****....        Emery Zboncak
 2) 254 ************.......        Whitney Effertz
 3) 134 *******............        Ezra Parisian
 4)  72 ****...............        Asha Gerlach
 5)  54 ****...............        Frederik Robel
 6)  20 *..................        Graciela Herzog
 7)   0 ...................        Thad Prohaska
命令缩写
可以使用命令的非歧义性前缀代替完整命令名称。例如,您可以使用 aoc r,aoc re 或 aoc rea 代替 aoc read。同样
- 您可以使用 c,ca,cal等,而不是calendar
- 您可以使用 d,do,dow,down等,而不是download
- 您可以使用 p,pr,pri等,而不是private-leaderboard
- 您可以使用 s,su,sub等,而不是submit
更多示例
下载前一天的谜题(假定是当前年份)
# aoc download --day 1
下载前一年的谜题输入,并将其保存为给定名称的文件
# aoc download --year 2015 --day 1 --input-only --input-file /home/user/aoc/2015/1/input
尝试下载仍然锁定中的谜题将失败(谜题每天在午夜 EST/UTC-5 的 1 日至 25 日之间解锁)
# aoc download --year 2030 --day 25
[INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool
[ERROR aoc] 🔔 Puzzle 25 of 2030 is still locked
提交前一年的答案
# aoc s 1 999 -y 2015 -d 1
指定会话 cookie 文件的路径
# aoc download --session-file /tmp/.aoc.session
贡献 🦌
欢迎反馈和 pull 请求。请参阅 CONTRIBUTING 了解指南和想法。
支持 Advent of Code 🎁
Advent of Code 是由 Eric Wastl 创建并由志愿者维护的免费在线 Advent 日历,其中包含小型编程谜题。请考虑 支持他们的工作。
依赖关系
~10–26MB
~412K SLoC