aoc-get: init helper script

This commit is contained in:
Antoine Martin 2021-12-06 15:05:29 +01:00
parent 7077559b3a
commit 6bb234ee6a
3 changed files with 77 additions and 0 deletions

39
aoc-get/aoc-get Executable file
View 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
View 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}
'';
}

View file

@ -18,9 +18,15 @@
nixpkgs-fmt nixpkgs-fmt
rust-analyzer rust-analyzer
myRust myRust
self.packages.${system}.aoc-get
]; ];
RUST_SRC_PATH = "${pkgs.rust-bin.stable.latest.rust-src}/lib/rustlib/src/rust/library"; RUST_SRC_PATH = "${pkgs.rust-bin.stable.latest.rust-src}/lib/rustlib/src/rust/library";
}; };
packages = {
aoc-get = pkgs.callPackage ./aoc-get {};
};
}); });
} }