54 lines
1.5 KiB
Fish
Executable file
54 lines
1.5 KiB
Fish
Executable file
#!/usr/bin/env fish
|
|
|
|
function usage
|
|
printf "Usage: %s [OPTIONS]\n\n" (status -f)
|
|
printf "Options:\n"
|
|
printf " -h/--help Prints help and exits\n"
|
|
printf " -d/--day=NUM Day (minimum 1, maximum 25)\n"
|
|
printf " -y/--year=NUM Year (minimum 2015, default current year)\n"
|
|
end
|
|
|
|
set --local options
|
|
set --append options (fish_opt --short h --long help)
|
|
set --append options (fish_opt --short d --long day --required-val)"!_validate_int --min 1 --max 25"
|
|
set --append options (fish_opt --short y --long year --required-val)"!_validate_int --min 2015"
|
|
|
|
if not argparse $options -- $argv
|
|
exit 1
|
|
end
|
|
|
|
if set --query _flag_help
|
|
usage
|
|
exit 0
|
|
end
|
|
|
|
# automatically set day if we're in December, otherwise require a value
|
|
set --local flag_day
|
|
if set --query _flag_day
|
|
set flag_day _flag_day
|
|
else
|
|
set --local month (date +%-m)
|
|
if [ $month -eq 12 ]
|
|
set flag_day (date +%-d)
|
|
else
|
|
echo "Please provide a day to fetch"
|
|
exit 1
|
|
end
|
|
end
|
|
|
|
set --query _flag_year; or set --local _flag_year (date +%Y)
|
|
|
|
if not set --query AOC_SESSION
|
|
echo "Please provide a session cookie via the AOC_SESSION environment variable"
|
|
exit 1
|
|
end
|
|
|
|
set --local padded_day (string pad --width 2 --char 0 {$flag_day})
|
|
set --local outpath aoc{$_flag_year}/input/day{$padded_day}.txt
|
|
|
|
echo "Saving input to" {$outpath} "..."
|
|
|
|
curl https://adventofcode.com/{$_flag_year}/day/{$flag_day}/input \
|
|
--cookie "session="{$AOC_SESSION} \
|
|
--output {$outpath}
|