aoc-get: init helper script
This commit is contained in:
parent
7077559b3a
commit
6bb234ee6a
39
aoc-get/aoc-get
Executable file
39
aoc-get/aoc-get
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/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"
|
||||
|
||||
argparse $options -- $argv
|
||||
|
||||
set --query _flag_year; or set --local _flag_year (date +%Y)
|
||||
|
||||
if set --query _flag_help
|
||||
usage
|
||||
exit 0
|
||||
end
|
||||
|
||||
if not set --query _flag_day
|
||||
echo "Please provide a day to fetch"
|
||||
exit 1
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
curl https://adventofcode.com/{$_flag_year}/day/{$_flag_day}/input \
|
||||
--cookie "session="{$AOC_SESSION} \
|
||||
--output aoc{$_flag_year}/input/day{$padded_day}.txt
|
32
aoc-get/default.nix
Normal file
32
aoc-get/default.nix
Normal file
|
@ -0,0 +1,32 @@
|
|||
{ lib
|
||||
, curl
|
||||
, makeWrapper
|
||||
, stdenvNoCC }:
|
||||
stdenvNoCC.mkDerivation rec {
|
||||
pname = "aoc-get";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./aoc-get;
|
||||
|
||||
buildInputs = [
|
||||
makeWrapper
|
||||
];
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
|
||||
wrapperPath = lib.makeBinPath [
|
||||
curl
|
||||
];
|
||||
|
||||
fixupPhase = ''
|
||||
patchShebangs $out/bin/${pname}
|
||||
wrapProgram $out/bin/${pname} --prefix PATH : "${wrapperPath}"
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $src $out/bin/${pname}
|
||||
chmod a+x $out/bin/${pname}
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue